Skip to main content
 首页 » 编程设计

python之如何使用 django 在生产服务器上修复模板不存在错误

2025年05月04日32bluestorm

更新:参见 self 回答。我在进行更改时未能重新启动 apache。

当我尝试在生产服务器中运行我的 Django 应用程序时,我收到以下关于查找模板的错误。我相信这与模板的存储位置有关;我已经更改了我的设置文件中的目录,但我想我可能错过了另一个地方。

我试图找到引用“C:/django/booking/reserve”的位置,因为这是给定的路径,但我似乎无法弄清楚在哪里。有什么建议吗?

Exception Type: TemplateDoesNotExist 
Exception Value:    reserve/templates/index.html 
Exception Location: /home/sharataka/webapps/django/lib/python2.7/django/template/loader.py in find_template, line 138 
Python Path:    ['/home/sharataka/webapps/django', 
 '/home/sharataka/webapps/django/booking', 
 '/home/sharataka/webapps/django/reserve', 
 '/home/sharataka/webapps/django/lib/python2.7', 
 '/home/sharataka/lib/python2.7/South-0.7.5-py2.7.egg', 
 '/home/sharataka/lib/python2.7/pip-1.1-py2.7.egg', 
 '/home/sharataka/lib/python2.7/django_debug_toolbar-0.9.4-py2.7.egg', 
 '/home/sharataka/lib/python2.7', 
 '/usr/local/lib/python27.zip', 
 '/usr/local/lib/python2.7', 
 '/usr/local/lib/python2.7/plat-linux2', 
 '/usr/local/lib/python2.7/lib-tk', 
 '/usr/local/lib/python2.7/lib-old', 
 '/usr/local/lib/python2.7/lib-dynload', 
 '/usr/local/lib/python2.7/site-packages', 
 '/usr/local/lib/python2.7/site-packages/PIL'] 
 
Django tried loading these templates, in this order: 
•   Using loader django.template.loaders.filesystem.Loader: 
o   /home/sharataka/C:/django/booking/reserve/templates/index.html (File does not exist 

设置.py

TEMPLATE_LOADERS = ( 
    'django.template.loaders.filesystem.Loader', 
    'django.template.loaders.app_directories.Loader', 
#     'django.template.loaders.eggs.Loader', 
) 
 
 
STATIC_ROOT = '/webapps/django/' 
 
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. 
    "/webapps/django", 
) 

请您参考如下方法:

我在进行更改时未能重新启动 apache...我是 django 菜鸟 :)