Django使用wag

时间:2018-03-07 17:54:24

标签: django debugging wagtail django-debug-toolbar

我想让django-debug-toolbar工作。我已经关注了installation steps,我得到了侧栏,包括统计数据(例如,2.75毫秒的SQL 1查询,使用的静态文件19个文件,12个信号的30个接收器),这些似乎是合法的并且表明它正在工作。

然而,当我点击给定标签上的更多信息时,我在浏览器中获得了404,并且在控制台中有这样的东西:

"GET /__debug__/render_panel/?store_id=ac74875cfe864b2dab4c6d17c1d1ed5d&panel_id=RequestPanel HTTP/1.1" 404 1791"

网站上的其他网页可以正常运作。

我在urls.py尝试了各种配置。这是我现在拥有的:

from __future__ import absolute_import, unicode_literals

from django.conf import settings
from django.conf.urls import include, url
from django.contrib import admin

from wagtail.wagtailadmin import urls as wagtailadmin_urls
from wagtail.wagtailcore import urls as wagtail_urls
from wagtail.wagtaildocs import urls as wagtaildocs_urls

from search import views as search_views

urlpatterns = [
    url(r'^django-admin/', include(admin.site.urls)),

    url(r'^admin/', include(wagtailadmin_urls)),
    url(r'^documents/', include(wagtaildocs_urls)),

    url(r'^search/$', search_views.search, name='search'),

    # For anything not caught by a more specific rule above, hand over to
    # Wagtail's page serving mechanism. This should be the last pattern in
    # the list:
    url(r'', include(wagtail_urls)),

    # Alternatively, if you want Wagtail pages to be served from a subpath
    # of your site, rather than the site root:
    #    url(r'^pages/', include(wagtail_urls)),
]
import debug_toolbar
urlpatterns += [
    url(r'^__debug__/', include(debug_toolbar.urls)),
]

if settings.DEBUG:
    from django.conf.urls.static import static
    from django.contrib.staticfiles.urls import staticfiles_urlpatterns


    # Serve static and media files from development server
    # urlpatterns = [
    #     url(r'^__debug__/', include(debug_toolbar.urls)),
    # ]
    urlpatterns += staticfiles_urlpatterns()
    urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

我在这里尝试了一些其他配置,包括:

import debug_toolbar
urlpatterns += [
    url(r'^__debug__/', include(debug_toolbar.urls)),
]

if settings.DEBUG:区块中。

有什么想法吗?

1 个答案:

答案 0 :(得分:3)

正如评论所说,令人不快的网址必须是最后一种模式。

一个选项是将调试工具栏网址移动到列表的开头:

urlpatterns = [
    ...
]

if settings.DEBUG:
    urlpatterns = [
        url(r'^__debug__/', include(debug_toolbar.urls)),
    ] + urlpatterns

或者您可以从当前位置移除wagtail网址,并在if settings.DEBUG:阻止后添加它们。

if settings.DEBUG:
    urlpatterns += [
        url(r'^__debug__/', include(debug_toolbar.urls)),
    ]

urlpatterns += [
    url(r'', include(wagtail_urls)),
]

我已将调试工具栏网址和if settings.DEBUG:块包含在此处,因为这是文档推荐的内容,但这并不是它工作的原因。关键是要确保最后的w ur网址。