M
M
Maxim2014-12-12 11:21:41
Django
Maxim, 2014-12-12 11:21:41

Why doesn't django return 404?

When DEBUG=False the 404th page is returned normally, if I set DEBUG=True , I get a 500th error and the message A server error occurred. Please contact the administrator.
Tell me which way to dig?
I came across the fact that the problem may be in the middleware, I have them declared like this:

MIDDLEWARE_CLASSES = (
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.cache.UpdateCacheMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.cache.FetchFromCacheMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
    'django.middleware.gzip.GZipMiddleware',
    'django.middleware.http.ConditionalGetMiddleware',
)

Traceback (most recent call last):
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/wsgiref/handlers.py", line 85, in run
    self.result = application(self.environ, self.start_response)
  File "/Users/or6/PycharmProjects/env/lib/python2.7/site-packages/django/contrib/staticfiles/handlers.py", line 64, in __call__
    return self.application(environ, start_response)
  File "/Users/or6/PycharmProjects/env/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 187, in __call__
    response = self.get_response(request)
  File "/Users/or6/PycharmProjects/env/lib/python2.7/site-packages/django/core/handlers/base.py", line 146, in get_response
    response = debug.technical_404_response(request, e)
  File "/Users/or6/PycharmProjects/env/lib/python2.7/site-packages/django/views/debug.py", line 518, in technical_404_response
    'reason': force_bytes(exception, errors='replace'),
  File "/Users/or6/PycharmProjects/env/lib/python2.7/site-packages/django/utils/encoding.py", line 150, in force_bytes
    errors) for arg in s])
  File "/Users/or6/PycharmProjects/env/lib/python2.7/site-packages/django/utils/encoding.py", line 151, in force_bytes
    return six.text_type(s).encode(encoding, errors)
UnicodeEncodeError: 'ascii' codec can't encode characters in position 42-45: ordinal not in range(128)
[12/Dec/2014 11:18:04] "GET /js HTTP/1.1" 500 59

UPD: Cyrillic is not used in urls.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
O
Oscar Django, 2014-12-12
@winordie

Last paragraph of this paragraph
If DEBUG is set to True (in the project settings), the 404 error handling view will never be used, and the URLconf with debugging information will be shown.
But in fact: it is obvious that the problem is in the Cyrillic alphabet. Perhaps Cyrillic was used somewhere along the way.

Z
zelsky, 2014-12-14
@zelsky

Virovlnyal approximately.

from django.http import Http404
from django.http import HttpResponse

def vieuha(request, param):
    try:
        param  = int(poluchaemui)
     except ValueError:
        raise Http404
     else:
           return HttpResponse('<h1>Hello World</h1>')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question