2013-03-11 77 views
0

环境:获取TemplateDoesNotExist错误时,Django部署应用到pr0duction服务器

在AWS上的Ubuntu
Django的1.4.5在virtalenv
Apache的2.2 WSGI

Django的setting.py:

TEMPLATE_DIRS = (os.path.join(os.path.dirname(__file__), '..', 'templates').replace('\\', '/'),) 

Apache2的错误日志:

[Mon Mar 11 22:18:55 2013] [error] [client 116.238.171.102] mod_wsgi (pid=1794): Exception occurred processing WSGI script '/home/ubuntu/Sites/tushanwan/tushanwan/wsgi.py'. 
[Mon Mar 11 22:18:55 2013] [error] [client 116.238.171.102] Traceback (most recent call last): 
[Mon Mar 11 22:18:55 2013] [error] [client 116.238.171.102] File "/home/ubuntu/.virtualenvs/django-1.4.5/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 241, in __call__ 
[Mon Mar 11 22:18:55 2013] [error] [client 116.238.171.102] File "/home/ubuntu/.virtualenvs/django-1.4.5/lib/python2.7/site-packages/django/core/handlers/base.py", line 179, in get_response 
[Mon Mar 11 22:18:55 2013] [error] [client 116.238.171.102] File "/home/ubuntu/.virtualenvs/django-1.4.5/lib/python2.7/site-packages/django/core/handlers/base.py", line 228, in handle_uncaught_exception 
[Mon Mar 11 22:18:55 2013] [error] [client 116.238.171.102] File "/home/ubuntu/.virtualenvs/django-1.4.5/lib/python2.7/site-packages/django/utils/decorators.py", line 91, in _wrapped_view 
[Mon Mar 11 22:18:55 2013] [error] [client 116.238.171.102] File "/home/ubuntu/.virtualenvs/django-1.4.5/lib/python2.7/site-packages/django/views/defaults.py", line 32, in server_error 
[Mon Mar 11 22:18:55 2013] [error] [client 116.238.171.102] File "/home/ubuntu/.virtualenvs/django-1.4.5/lib/python2.7/site-packages/django/template/loader.py", line 145, in get_template 
[Mon Mar 11 22:18:55 2013] [error] [client 116.238.171.102] File "/home/ubuntu/.virtualenvs/django-1.4.5/lib/python2.7/site-packages/django/template/loader.py", line 138, in find_template 
[Mon Mar 11 22:18:55 2013] [error] [client 116.238.171.102] TemplateDoesNotExist: 500.html 

我花了一天时间,尝试了很多方法来解决我的aws ubuntu实例上的这个问题,但是他们也没有为我工作。我使用相同的方式在本地ubuntu服务器上部署django应用程序,并且它可以工作。

+0

你有没有设置你的DEBUG = TRUE? – catherine 2013-03-11 15:28:20

+0

我将它设置为False – 2013-03-11 16:01:04

回答

3

来自:https://docs.djangoproject.com/en/dev/topics/http/views/#the-500-server-error-view

如果DEBUG设置为True(在设置模块),那么你的500视图 将永远不会被使用,并且回溯将改为显示,与 一些调试信息。

因此而在你的开发服务器的一切可以正常工作,如果在生产服务器上,你没有一个500.html(在你的模板文件夹的根目录),然后框架将上升一个错误。

附注:Django 1.4.x中需要404.html和500.html文件;在Django 1.5.x中,500.html和404.html文件不再是严格要求的,谢谢to this patch

+0

我向我的模板添加了500.html。但仍然在我的apache错误日志文件中出现TemplateDoesNotExist错误,并添加了500.html的呈现。 – 2013-03-11 16:08:51

+0

你有没有重新启动apache?是500.html文件权限好吗? – furins 2013-03-11 16:43:27

+0

是的,apache已重新启动,500.html的权限是644. – 2013-03-12 00:57:34

相关问题