Django internal server error instead of 404

I am using Django 1.6, uwsgi and nginx, the application works fine, but I get 500 errors and emailed below for every invalid url that I am trying to access, instead of 404 error.

I get this for http://my_project_url.com/whatever or even for http://my_project_url.com/favicon.ico

I looked at the url but there is no regular expression matching this pattern.

Here is the trace from the letter:

Traceback (most recent call last):

  File "/project/virtenv/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 152, in get_response
    response = callback(request, **param_dict)

  File "/project/virtenv/local/lib/python2.7/site-packages/django/utils/decorators.py", line 99, in _wrapped_view
    response = view_func(request, *args, **kwargs)

  File "/project/virtenv/local/lib/python2.7/site-packages/django/views/defaults.py", line 30, in page_not_found
    body = template.render(RequestContext(request, {'request_path': request.path}))

  File "/project/virtenv/local/lib/python2.7/site-packages/debug_toolbar/panels/templates/panel.py", line 55, in _request_context__init__
    context = processor(request)

  File "./project/context_processors.py", line 88, in app_delegate
    app_name = resolve(request.path).app_name

  File "/project/virtenv/local/lib/python2.7/site-packages/django/core/urlresolvers.py", line 453, in resolve
    return get_resolver(urlconf).resolve(path)

  File "/project/virtenv/local/lib/python2.7/site-packages/django/core/urlresolvers.py", line 333, in resolve
    raise Resolver404({'tried': tried, 'path': new_path})

Resolver404: {u'path': u'favicon.ico', u'tried': [[<RegexURLResolver <module 'custom_

If I try to access the url from the application where I am running raise Http404, this is normal, I get the normal nginx error page.

+4
1

, , :

File "./project/context_processors.py", line 88, in app_delegate
  app_name = resolve(request.path).app_name

django solve() docs:

URL- , Resolver404 ( Http404).

, :

try:
    resolve_result = resolve(request.path)
    app_name = resolve_result.app_name
    ... your code ....
except Resolver404:
    pass
+7

Source: https://habr.com/ru/post/1544313/


All Articles