Windows 7
Python 2.7.3
Django 1.5
python manage.py runserver
我正在关注" https://docs.djangoproject.com/en/1.5/intro/tutorial03/ "上提供的教程.
在事情变得奇怪之前,我得到了"写一个404(页面未找到)视图".
我试图找出如何制作自定义404视图.但是,我不确定:
答:自定义404.html文件应该驻留在哪里.它应该在我的项目目录树中还是在我的Django目录树中.我的项目目录树看起来像这样,
1> mysite
2> - mysite
3> - polls
4> - templates
5> - polls
6> - templates
7> - admin
Run Code Online (Sandbox Code Playgroud)
目前404.html是@ 6>
B.必须在哪些地方进行哪些修改?我知道需要在'root'url conf中设置handler404和handler500.我有一个url.py驻留在@ 2>和3>(参见上面的树).假设2>是正确的位置我假设语法如下,
handler404 = 'templates.404'
handler500 = 'templates.500'
Run Code Online (Sandbox Code Playgroud)
还需要设置什么,在哪里?
Windows 7
Python 2.7.3
Django 1.5
python manage.py runserver
我正在关注" https://docs.djangoproject.com/en/1.5/intro/tutorial03/ "上提供的教程.
在settings.py中使用DEBUG = True可以正确生成网页.地址
http://127.0.0.1:8000/admin/
Run Code Online (Sandbox Code Playgroud)
显示管理员登录页面.
http://127.0.0.1:8000/polls/
Run Code Online (Sandbox Code Playgroud)
显示'什么事?' 项目符号链接.
http://127.0.0.1:8000/polls/1/
Run Code Online (Sandbox Code Playgroud)
显示数字'1'
http://127.0.0.1:8000/polls/2/
Run Code Online (Sandbox Code Playgroud)
显示标准404消息.但是,如果我设置DEBUG = False(并且不执行任何其他操作),那么我在所有地址都会出现500错误!我正在使用开发内部运行服务器.没有回溯错误.服务器日志如下所示:
DEBUG = True
0 errors found
March 19, 2013 - 12:01:12
Django version 1.5, using settings 'mysite.settings'
Development server is running at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
[19/Mar/2013 12:06:41] "GET /admin/ HTTP/1.1" 200 1893
[19/Mar/2013 12:54:55] "GET /polls/ HTTP/1.1" 200 74
[19/Mar/2013 12:55:02] "GET /polls/2/ HTTP/1.1" 404 1577
[19/Mar/2013 12:55:09] "GET /polls/1/ HTTP/1.1" …Run Code Online (Sandbox Code Playgroud)