You should check how it is done in rails.vim, the Rails plugin from Tim Pope, which works that way.
If you are editing a *.rb (Ruby file) from a Rails project, you enable some specific Rails configuration. But not if you are editing a non-Rails ruby file.
You should check the source code yourself but the entry point of the detection is below :
augroup railsPluginDetect
autocmd!
autocmd BufNewFile,BufRead * call s:Detect(expand("<afile>:p"))
autocmd VimEnter * if expand("<amatch>") == "" && !exists("b:rails_root") | call s:Detect(getcwd()) | endif | if exists("b:rails_root") | silent doau User BufEnterRails | endif
autocmd FileType netrw if !exists("b:rails_root") | call s:Detect(expand("<afile>:p")) | endif | if exists("b:rails_root") | silent doau User BufEnterRails | endif
autocmd BufEnter * if exists("b:rails_root")|silent doau User BufEnterRails|endif
autocmd BufLeave * if exists("b:rails_root")|silent doau User BufLeaveRails|endif
autocmd Syntax railslog if s:autoload()|call rails#log_syntax()|endif
augroup END
Basically what s:Detect
does is finding the root of the Rails project and check if there is an ./config/environment.rb
and if this is the case, it create an event BufEnterRails
with silent doau User BufEnterRails
and there is another autocommand in case BufEnterRails happens.
You must follow the same path for your plugin. On opening a buffer, you should try to find a specific Django file or directory in the html file path you are editing, and then decide if you are in a Django project or not.
Since I don't know Django, I can't tell which file to look for, but there is likely a project config file common to every Django project.