Django tutorials: 500 @debug = false

Windows 7
Python 2.7.3
Django 1.5
python manage.py runningerver

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

with DEBUG = True in settings.py the web pages are created correctly. The address

http://127.0.0.1:8000/admin/  

Displays the admin login page.

http://127.0.0.1:8000/polls/  

displays "what?" bulleted link.

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

displays the number '1'

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

displays a standard 404 message. However, if I set DEBUG = False (and do nothing), I get a 500 error in ALL ADDRESSES! I am using an internal development server. No trace errors. The server log is as follows:

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  

"manage.py" @1 > , , .

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

:
A. view.py '@2 > , ? "view.py" @3 > ; B. "404.html" @2 > (@4 > @6 > )? , "500.html" .

, .

+5
5

, ALLOWED_HOSTS .

+10

, , 404.html , ALLOWED_HOSTS -

+5

, , , django mysite:

# mysite/mysite/settings.py
DEBUG = False
ALLOWED_HOSTS = ['localhost']
# Tells your project to find your custom 404.html at mysite/mysite/templates/404.html
INSTALLED_APPS = (..., 'tutorial', ...)

# mysite/mysite/urls.py
handler404 = 'tutorial.views.custom_404'

# mysite/mysite/views.py
from django.shortcuts import render

def custom_404(request):
    return render(request, '404.html', {}, status=404)

# mysite/mysite/templates/404.html
<h1>CUSTOM 404 PAGE</h1>

. = P


:

mysite  
    - mysite
        - settings.py
        - urls.py
        - views.py
        - templates
            - 404.html  
    - polls  
        - templates  
            - polls
+4

python manage.py runningerver localhost: 8000

,

python manage.py runningerver 0.0.0.0:8000

0

:

  • 404.html
  • python manage.py collectstatic --noinput

And that solved the error for me.

0
source

All Articles