gpt4 book ai didi

python - Django 内部服务器错误而不是 404

转载 作者:太空狗 更新时间:2023-10-30 02:20:17 24 4
gpt4 key购买 nike

我使用的是 Django 1.6、uwsgi 和 nginx,该应用程序运行良好,但我收到 500 错误和下面针对我尝试访问的每个无效 URL 的电子邮件,而不是 404 错误。

我得到这个 http://my_project_url.com/whatever甚至是 http://my_project_url.com/favicon.ico

我查看了 URL,但没有匹配此模式的正则表达式。

这是来自电子邮件的追溯:

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_

如果我尝试从应用程序访问一个 URL,我在其中执行 raise Http404 没问题,我会收到常规的 nginx 错误页面。

最佳答案

似乎您有一个自定义处理器试图解析路径:

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

引用 django resolve()文档:

If the URL does not resolve, the function raises a Resolver404 exception (a subclass of Http404) .

我建议您在自定义处理器中管理异常代码如下:

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

关于python - Django 内部服务器错误而不是 404,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24182850/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com