sách gpt4 ai đã đi

Thanh công cụ gỡ lỗi Django hiển thị trong URL gốc nhưng không hiển thị trong URL ứng dụng

In lại 作者:行者123 更新时间:2023-12-05 04:15:17 33 4
mua khóa gpt4 Nike

我有一个新项目,我正在尝试设置 Django 调试工具栏。首先,我尝试了快速设置,它只涉及将 'debug_toolbar' 添加到我的已安装应用程序列表中。有了这个,当我转到我的根 URL 时,调试工具栏出现了,但它不适用于我的应用程序 url/ View 。我现在不应该,我的根 URL 没有链接到 View ,所以它显示了一个 Django 错误页面。

由于快速启动不起作用,我选择了显式设置。我更新了我的设置文件:

DEBUG_TOOLBAR_PATCH_SETTINGS = False

MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'debug_toolbar.middleware.DebugToolbarMiddleware',
)

并更新了我的项目级 urls.py:

if settings.DEBUG: # make sure the toolbar is above ?CKeditor and FeinCMS
import debug_toolbar
urlpatterns += patterns('',
url(r'^__debug__/', include(debug_toolbar.urls)),
)

但现在它没有出现在任何地方。

在我的应用程序 View 中,我向模板添加了一个 {% debug %}。模板调试输出似乎表明调试工具栏中间件已加载:

 'debug_toolbar': ,
'debug_toolbar.collections': None,
'debug_toolbar.compat': ,
'debug_toolbar.django': None,
'debug_toolbar.importlib': None,
'debug_toolbar.middleware': ,

我不确定为什么这不起作用。我的 django 版本是 1.8,我的调试工具栏版本是 1.3.2。

1 Câu trả lời

我对这个问题的解决方案是添加 标签到模板。

我是从 django-debug-toolbar 网站上的“提示”部分得到的。

The Debug Toolbar will only display when DEBUG = True in your project’s settings. It will also only display if the mimetype of the response is either text/html or application/xhtml+xml and contains a closing nhãn.

nguồn:django-debug-toolbar.readthedocs.io/en/stable/tips.html

如果工具栏在索引页面(或任何其他页面)上有效但在另一个页面上无效,则可能是缺少 body 标签的原因。

关于Django 调试工具栏显示在根 URL 中,但不显示在应用程序 URL 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32791313/

33 4 0
行者123
Hồ sơ cá nhân

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá Didi Taxi miễn phí
Mã giảm giá Didi Taxi
Giấy chứng nhận ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com