gpt4 book ai didi

Clicking on Django debug toolbar tabs results in 404 Not Found error(单击Django调试工具栏选项卡导致404未找到错误)

转载 作者:bug小助手 更新时间:2023-10-28 11:26:58 27 4
gpt4 key购买 nike



I am trying to analyze and optimize my sql queries in my Django 1.10 project, and for this reason trying to setup Django Debug Toolbar. For now, I can see the toolbar appear on the left side of my browser, but when I click the tabs, I end up with 404 error.enter image description here

我正在尝试分析和优化Django 1.10项目中的SQL查询,并因此尝试设置Django Debug工具栏。目前,我可以看到工具栏出现在浏览器的左侧,但当我单击选项卡时,结果显示404错误。




GET
http://127.0.0.1:8000/debug/render_panel/?store_id=10d77fee31c2425aafb5a2cd7898111f&panel_id=SQLPanel
404 (Not Found)




My URLConf file:

我的URLConf文件:



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

urlpatterns += (
url(r'', include('my_project_urls.urls')),
# ...
)


settings.py (only relevant content):

Settings.py(仅限相关内容):



ROOT_URLCONF = 'android_blend.urls'
PROJECT_ROOT = os.path.abspath(os.path.dirname(__file__))
STATIC_URL = '/static/'

if DEBUG:
MEDIA_URL = '/media/'
STATIC_ROOT = os.path.join(os.path.dirname(BASE_DIR),"static","static-only")
#STATIC_ROOT = [os.path.join(BASE_DIR,"static-only")]
MEDIA_ROOT = os.path.join(os.path.dirname(BASE_DIR),"static","media")
#MEDIA_ROOT = [os.path.join(BASE_DIR,"media")]
STATICFILES_DIRS = (
os.path.join(BASE_DIR,"static"),
)

def show_toolbar(request):
if not request.is_ajax() and request.user and request.user.id == 4:
return True
return False

DEBUG_TOOLBAR_CONFIG = {'SHOW_TOOLBAR_CALLBACK': 'android_blend.settings.show_toolbar'}


I blame the error on an erroneous settings regarding static files. In the cmd, when I navigate to the project root folder and run python manage.py collectstatic, I see a folder named static appear on my Desktop, instead of project root. I manually copied the static-only folder which was in the newly created static folder into the static folder of my project root, but again no success. Could anyone help me with finding the solution ? Any hint would be appreciated.

我将错误归咎于关于静态文件的错误设置。在cmd中,当我导航到项目根文件夹并运行pythonmarke.py收集器时,我看到一个名为Static的文件夹出现在我的桌面上,而不是项目根目录。我手动将新创建的静态文件夹中的仅静态文件夹复制到我的项目根目录的静态文件夹中,但同样没有成功。有人能帮我找到解决方案吗?如有任何提示,我们将不胜感激。


更多回答
优秀答案推荐

I don't know if you already found it but there has been a breaking change which was "announced" here:

我不知道你是否已经找到它,但有一个突破性的变化,它是在这里宣布的:



https://github.com/jazzband/django-debug-toolbar/issues/954

Https://github.com/jazzband/django-debug-toolbar/issues/954



and documented here:

并在此处进行了记录:



https://github.com/jazzband/django-debug-toolbar/pull/961/commits/22c22d719e856045e76b399d4e4ab5dc5e3fc040

Https://github.com/jazzband/django-debug-toolbar/pull/961/commits/22c22d719e856045e76b399d4e4ab5dc5e3fc040




For versions < 1.8, the callback should also return False for AJAX requests. Since version 1.8, AJAX requests are checked in the middleware, not the callback. This allows reusing the callback to verify access to panel views requested via AJAX.




So your code should be fine like this:

因此,您的代码应该是这样的:



def show_toolbar(request):
if request.user and request.user.id == 4:
return True
return False


For me, I put the __debug__ URL above the static and media routes and then it works.

对我来说,我把__debug__ URL放在静态和媒体路由之上,然后它就可以工作了。


if settings.DEBUG:
urlpatterns.append(path('__debug__/', include('debug_toolbar.urls')))
urlpatterns += static(settings.STATIC_URL,
document_root=settings.STATIC_ROOT)
urlpatterns += static(settings.MEDIA_URL,
document_root=settings.MEDIA_ROOT)


From a recent django-debug-toolbar version (1.9.1), I've downgraded to an older one (1.6) and I'm no longer getting a 404.

从最近的Django-DEBUG-TOOLBAR版本(1.9.1),我已经降级到更老的版本(1.6),我不再得到404。



I am also getting 404s for all, But after rearranging the MIDDLEWARE debug_toolbar.middleware.DebugToolbarMiddleware higher as much as possible, My problem is solved.
Just keep in mind that The order of MIDDLEWARE is important. You should include the Debug Toolbar middleware as early as possible in the list, which is also mentioned in the documents. Add the Middleware

我也都得到了404,但在尽可能高地重新排列中间件debug_toolbar.middleware.DebugToolbarMiddleware后,我的问题就解决了。请记住,中间件的顺序很重要。您应该尽可能早地将Debug工具栏中间件包括在列表中,文档中也提到了这一点。添加中间件


更多回答

I've did an upgrade for djdt 1.5 -> 1.9.1 and this was the problem: the callback.

我对djdt1.5->1.9.1进行了升级,问题是:回调。

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