Django 调试工具栏仅适用于管理部分

发布于 2024-11-01 17:29:19 字数 383 浏览 2 评论 0 原文

嘿, 我已经使用 Django 1.2.1 一段时间了,前几天遇到了 Django 调试工具栏。它看起来真的很有用,我真的很想尝试一些东西。

我完全按照自述文件所说的安装了。步步。我将中间件放在最后,以防万一出现问题,但我使用的是相当标准的中间件(common、sessions、auth 和 csrf)。但是,它不会显示在我的任何页面上。我尝试过移动中间件,但效果相同。

好像我安装了什么错误的东西。但是,当我加载 django 的管理部分时,工具栏就会弹出。我不确定我做错了什么。我的页面内容会影响出现的工具栏吗?它以 mime text/html 的形式输出...

无论如何,非常感谢任何帮助。提前致谢。

这是我的 Settings.py:pastebin.com/Hu8TgANt

Hey,
I've been using Django 1.2.1 for some time now and came across Django Debug Toolbar just the other day. It looks really useful and I'm really eager to try some stuff out.

I installed exactly how the readme said. Step by Step. I put the middleware at the end just in case things get caught up but I'm using quite standard middleware (common, sessions, auth and csrf). However, it won't show up on any of my pages. I've tried moving the middleware but to the same effect.

It seems as if I've installed something wrong. But, when I load up the Admin Section of django, the toolbar springs up. I'm not sure what I'm doing wrong. Can the content of my pages effect the toolbar coming up? It's outputting in the mime text/html...

Anyway, any help is greatly appreciated. Thanks in advance.

Here's my Settings.py: pastebin.com/Hu8TgANt

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

始终不够 2024-11-08 17:29:19

调试工具栏要求响应 HTML 中至少有一个结束 标记。

来更改此标记

可以通过更改 settings.DEBUG_TOOLBAR_​​CONFIG['INSERT_BEFORE'] http://django-debug-toolbar.readthedocs.org/en/latest/configuration.html#toolbar-options

Debug toolbar requires that there's at least a closing </body> tag in the response HTML.

This tag can be changed by changing settings.DEBUG_TOOLBAR_CONFIG['INSERT_BEFORE']

http://django-debug-toolbar.readthedocs.org/en/latest/configuration.html#toolbar-options

飞烟轻若梦 2024-11-08 17:29:19

在不知道您的代码的情况下的一些提示:

  • “debug_toolbar.middleware.DebugToolbarMiddleware”应该是您的最后一个或倒数第二个中间件条目(不能100%确定它如何与 flatpagefallback 中间件一起工作)
  • “debug-toolbar”作为列表中的最后一个INSTALLED_APPS
  • 仔细检查工具栏的资源是否已加载
  • 确保所有工具栏设置均已设置。 (DEBUG_TOOLBAR_​​CONFIG、INTERNAL_IPS)等。

错误应该在那里。我知道与在平面页面上显示工具栏相关的其他问题,因此如果您只在平面页面上检查,我建议您在另一个模块上尝试它。

A few tipps without knowing your code:

  • 'debug_toolbar.middleware.DebugToolbarMiddleware' should be your last or second to last middle ware entry (not 100% sure how it works out with the flatpagefallback middleware)
  • 'debug-toolbar' as last in the list of INSTALLED_APPS
  • Double check if the toolbar's assets are loaded
  • Make sure all toolbar settings are set. (DEBUG_TOOLBAR_CONFIG, INTERNAL_IPS) etc.

The error should be something in there. I know of other problems related getting the toolbar displayed on flatpages so if you only checked on flatpages I suggest you try it on another module.

倾城°AllureLove 2024-11-08 17:29:19

我在这里遇到了同样的问题,最终到达了这篇文章...无论如何,就我而言,我注意到我的 js 包含库之一有一个 javascript 错误。这打破了 js 解释流程。当我修复了 javascript 错误后,django 工具栏就可以工作了。

这解释了为什么它在管理页面中有效,但在我的应用程序页面中无效。

I had the same problem here, and eventually arrived at this post... Anyway, in my case what I noticed was that I had a javascript error in one of my js included libraries. And that breaked the js interpretation flow. When I fixed the javascript error, the django toolbar worked.

That explains why it worked in the admin pages, but not in my app pages.

怪我太投入 2024-11-08 17:29:19

settings.py 中缺少 INTERNAL_IPS 键会影响工具栏的可见性。添加此内容可以解决问题:

INTERNAL_IPS = ('127.0.0.1',)

Missing INTERNAL_IPS key in settings.py impacts toolbar visibility. Adding this resolves the issue:

INTERNAL_IPS = ('127.0.0.1',)
江南月 2024-11-08 17:29:19

就我而言,我使用 Google Material Design Lite 作为前端框架,

它具有样式定义,

*[hidden]{
    display:none!important;
}

该样式应用于调试工具栏的元素,导致不显示任何内容。

一个快速的解决方法是将 MDL 的样式定义(仅适用于本地样式表,不适用于托管的 cdn)更改为

*[hidden]{
    display:none;
}

In my case, I was using Google Material Design Lite as the frontend framework,

which has the style definition,

*[hidden]{
    display:none!important;
}

this style is applied to Debug Toolbar's elements which result in displaying nothing.

a quick workaround was to change the MDL's style definition (only possible on local stylesheets, not with cdn hosted) to

*[hidden]{
    display:none;
}
猫九 2024-11-08 17:29:19

我有类似的问题。解决方案是将 div 作为非空 HTML 元素关闭。

从这里

<body>
...
    <div id="map-canvas"/>
...
</body>

到这里

<body>
...
    <div id="map-canvas"></div>
...
</body>

希望有帮助!

I had a similar issue. The solution was closing a div as a non-empty HTML element.

From this

<body>
...
    <div id="map-canvas"/>
...
</body>

to this

<body>
...
    <div id="map-canvas"></div>
...
</body>

Hope it helps!

—━☆沉默づ 2024-11-08 17:29:19

就我而言,错误非常简单。

我删除了页脚,它的效果就像一个魅力!

希望这能为其他人解决问题。

In my case the error was very simple.

I removed the footer and it worked like a charm!

Hope this solves an issue for somebody else.

樱桃奶球 2024-11-08 17:29:19

就我而言,解决方案是硬刷新我的网页。
只需按 Ctrl+F5 即可

In my case the solution was to hard-refresh my webpage.
Simply hit Ctrl+F5 and that's it

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文