升级至Django 1.11后加载Admin页面出现TemplateDoesNotExist错误
Hey, sorry to hear you've been stuck on this for three days—let's get this sorted out. The TemplateDoesNotExist: admin/index.html error in your Django 1.11 upgrade (with django-jet) is almost certainly tied to template configuration issues or compatibility gaps. Here are the targeted fixes to try:
1. Fix your TEMPLATES configuration (most likely root cause)
Looking at your current setup, you're missing the APP_DIRS: True flag. Django requires this to automatically search for templates inside installed apps (like django.contrib.admin and django-jet). Without it, Django will only check the custom directories you listed in DIRS—which don't include the admin or jet template files.
Update your TEMPLATES setting to add this critical line:
TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': [ os.path.join(BASE_DIR, 'custom_dir_1'), os.path.join(BASE_DIR, 'custom_dir_2'), os.path.join(BASE_DIR, 'custom_dir_3') ], 'APP_DIRS': True, # Add this line! 'OPTIONS': { 'context_processors': [ 'django.contrib.auth.context_processors.auth', 'django.template.context_processors.request', 'django.template.context_processors.i18n', 'django.contrib.messages.context_processors.messages', 'context_processors.base_context', ], } } ]
2. Verify django-jet compatibility & INSTALLED_APPS order
Django-jet version 1.0.8 is the last release that supports Django 1.11—older versions won’t work with your upgraded framework. Run this to install/update to the compatible version:
pip install django-jet==1.0.8
Also, ensure jet comes before django.contrib.admin in your INSTALLED_APPS. This is critical because jet replaces the default admin templates, so Django needs to load jet's templates first:
INSTALLED_APPS = [ 'jet', # ... other apps ... 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', # ... your custom apps ... ]
3. Clear template caches
After making configuration changes, clear any cached templates to avoid old, invalid paths causing issues:
python manage.py clearcache
You can also manually delete any __pycache__ folders in your project directory for extra safety.
4. Double-check core admin dependencies are installed
Make sure all required admin-related apps are present in INSTALLED_APPS: django.contrib.admin, django.contrib.auth, django.contrib.contenttypes, django.contrib.sessions, django.contrib.messages, and django.contrib.staticfiles. These are essential for the admin to function, including loading its base templates.
If none of these steps resolve the issue, let me know—we can dive deeper into checking if jet's template files exist in your virtual environment or troubleshooting custom template loader settings.
内容的提问来源于stack exchange,提问作者doubleo

