你设置好
TEMPLATE_DIRS了
settings.py吗?检查并确保使用绝对路径正确设置了它。这是我确保正确设置的方式:
settings.pyPROJECT_ROOT = os.path.abspath(os.path.dirname(__file__))TEMPLATE_DIRS = ( # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates". # Always use forward slashes, even on Windows. # Don't forget to use absolute paths, not relative paths. os.path.join(PROJECT_ROOT, 'templates').replace('\','/'),)# List of callables that know how to import templates from various sources.TEMPLATE_LOADERS = ( 'django.template.loaders.filesystem.Loader', 'django.template.loaders.app_directories.Loader',# 'django.template.loaders.eggs.Loader',)这样,我
templates在项目根目录中有一个用于非应用程序模板的
templates/appname文件夹,每个应用程序内部都有一个文件夹。
如果要使用根模板文件夹中的模板
'base.html',则只需输入模板名称,例如,如果要使用应用程序模板,则使用
'appname/base.html'
资料夹结构:
project/ appname/ templates/ appname/ <-- another folder with app name so 'appname/base.html' is from here base.html views.py ... templates/ <-- root template folder so 'base.html' is from here base.html settings.py views.py ...



