Django 2.1.7模板不存在问题求助:3种Stack Overflow方案无效
Fixing Django 2.1.7 TemplateDoesNotExist Error for /munichlivingapp/seekers/
Hey there, let’s troubleshoot this template missing issue step by step—this is super common in Django, so we’ll get it sorted out quickly.
First, Let’s Cover the Basics You Might Have Missed
1. Confirm Your App is Registered in INSTALLED_APPS
Since you have APP_DIRS: True in your TEMPLATES config, Django will only look for templates inside apps that are listed in INSTALLED_APPS in settings.py. Double-check that your app (likely munichlivingapp) is included here:
INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'munichlivingapp', # Make sure this line exists! ]
2. Verify Your Template File Structure
Django expects templates to follow a specific structure to avoid naming conflicts:
- If using project-level templates (your
DIRSpoints to project root/templates):
Your template should be at[BASE_DIR]/templates/seekers/[your-template-name].html(match the exact path your view is trying to render). - If using app-level templates:
Create a nested folder inside your app’s templates directory:munichlivingapp/templates/munichlivingapp/seekers/[your-template-name].html. This ensures Django doesn’t mix up your templates with others from different apps.
3. Check Your View’s Template Call
Make sure the template path in your view matches the actual file path. For example:
- If using project-level templates:
return render(request, 'seekers/your_template.html') - If using app-level templates:
return render(request, 'munichlivingapp/seekers/your_template.html')
Fixes for Your TEMPLATES Config
Let’s refine the solutions you tried:
- Your first solution (
os.path.join(BASE_DIR, "templates")) is correct, but confirmBASE_DIRis pointing to the right place. Add a quick debug line insettings.pyto check:
Ensure this path is your project’s root directory (whereprint("BASE_DIR is:", BASE_DIR) # Run the server and check the console outputmanage.pylives). - Solution 2 (
'DIRS': ['templates']) might fail if your server’s working directory isn’t the project root. Stick with theos.path.joinversion—it’s more reliable across environments. - Solution 3 (
TEMPLATE_DIRS) is outdated—Django 1.8+ uses theTEMPLATESdictionary, so this setting won’t do anything in 2.1.7. Ignore it entirely.
Extra Troubleshooting Steps
- Check for spelling/case errors: Linux systems are case-sensitive! If your view calls
Seekers/home.htmlbut your folder is namedseekers, this will break. - Clear Django’s cache: Sometimes old template paths get cached. Run:
Then restart your development server.python manage.py clearcache - Verify file permissions: Ensure the user running your Django server has read access to the templates directory and files. On Linux, you can adjust permissions with:
chmod -R 755 /path/to/your/templates
内容的提问来源于stack exchange,提问作者Kami Barut
相关产品推荐
相关产品推荐

