You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Django3中使用include引入URL配置后模板无法显示的问题排查

Fixing Django's TemplateDoesNotExist Error for Your Dashboard App

Hey there, let's work through this template issue you're facing with your Django dashboard app—we've all been stuck on template path problems when starting out, so let's break down the fixes step by step:

1. Update the Template Path in Your View

Right now, your view is looking directly for dashboard.html, but your template lives inside dashboard/templates/dashboard/dashboard.html. Django searches for templates within each app's templates folder, so you need to include the subfolder name in the path.

Modify your dashboard view code to this:

from django.shortcuts import render

# Create your views here.
def dashboard(request):
    home="dashboard"
    # Use the full relative path inside the app's templates folder
    return render(request, 'dashboard/dashboard.html', {'home':home})

2. Confirm Your Dashboard App is in INSTALLED_APPS

Django only looks for templates in apps that are listed in your project's settings.py under INSTALLED_APPS. Double-check that you've added dashboard there:

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    # Make sure this line exists
    'dashboard',
]

3. Verify Your Folder Structure is Exact

Double-check that your template folder structure matches this exactly (pay attention to folder names and nesting):

your-project-root/
├─ dashboard/
│  ├─ templates/
│  │  ├─ dashboard/
│  │  │  └─ dashboard.html  # Your template file lives here
│  ├─ views.py
│  └─ urls.py

4. Check for Typos or Case Sensitivity

  • Make sure dashboard.html is spelled correctly (no typos like dashbaord.html).
  • On Linux/macOS, filenames are case-sensitive—if your file is named Dashboard.html instead of dashboard.html, Django won't find it.

Why base.html Loaded but Was Empty

When you switched to base.html, Django was likely finding a base.html file in your project's root templates folder (if you have one), but that file probably has no content or doesn't include the template blocks you need. This confirms that Django's template system is working—you just had the wrong path for your dashboard template.

Try these steps one by one, and your dashboard template should load properly. If you run into any other issues, feel free to share more details!

内容的提问来源于stack exchange,提问作者Nauman K

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.29 20:12:31