Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

django tutorials: 500 @ debug=false

Windows 7
Python 2.7.3
Django 1.5
python manage.py runserver

I am following the tutorial as available at 'https://docs.djangoproject.com/en/1.5/intro/tutorial03/'

with DEBUG=True in settings.py the webpages are generated correctly. The address

http://127.0.0.1:8000/admin/  

displays the admin login page.

http://127.0.0.1:8000/polls/  

displays the 'What's up?' bulleted link.

http://127.0.0.1:8000/polls/1/  

displays the number '1'

http://127.0.0.1:8000/polls/2/  

displays the standard 404 message. However if I set DEBUG=False (and do nothing else) then I get a 500 error at ALL ADDRESSES! I am using the development internal runserver. There are no traceback errors. The server log looks like this:

with 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" 200 1  
Validating models...  

with DEBUG=False

0 errors found  
March 19, 2013 - 12:55:21  
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:59:22] "GET /admin/ HTTP/1.1" 500 27  
[19/Mar/2013 12:59:25] "GET /polls/ HTTP/1.1" 500 27  
[19/Mar/2013 12:59:28] "GET /polls/1/ HTTP/1.1" 500 27  
[19/Mar/2013 12:59:34] "GET /polls/2/ HTTP/1.1" 500 27  

My directory structure is as follows:

1> mysite  
2>     - mysite  
3>     - polls  
4>         - templates  
5>             - polls  
6>     - templates  
7>         - admin  

My 'manage.py' is @ 1> so I understand that I have to make the edits in the following files&locations.

@ 2> the settings.py
@ 2> the urls.py

However:
A. I currently have no 'view.py' file @ 2>, would this be a new file? After following the tutorial I currently have a 'view.py' @ 3>;
B. Should the '404.html' go into a new templates directory under @2> or one of the two existing template directories (@4> or @6>)? I assume that a custom '500.html' would go into the same directory.

I would be happy to post any more of my code you want to look at.

like image 890
SeeGull Avatar asked Mar 19 '13 12:03

SeeGull


2 Answers

Most likely, you forgot to set ALLOWED_HOSTS in settings file.

like image 85
Zdeslav Vojkovic Avatar answered Nov 07 '22 11:11

Zdeslav Vojkovic


I had the same issue before, I was able to fix this by creating 404.html in my template directory, specifying valid ALLOWED_HOSTS and restarted my webserver

like image 41
helloworld2013 Avatar answered Nov 07 '22 12:11

helloworld2013