Django 调试工具栏安装问题

发布于 2024-10-18 10:58:50 字数 342 浏览 1 评论 0原文

我在尝试启动并运行 django-debug-toolbar 时遇到问题。我已将所有必要的信息添加到 INSTALLED_APPSMIDDLEWARE_CLASSES 中,并且我的 IP 位于 INTERNAL_IPS 元组中。我已经运行了 setup.py 脚本,一切似乎都加载得很好,因为我没有从 django 或 apache 收到任何错误。

但是,没有任何反应 - 任何页面上都没有工具栏,有其他人见过这种行为吗?我错过了一些明显的东西吗?

I am having issues trying to get the django-debug-toolbar up and running. I have all of the necessary info added to INSTALLED_APPS, MIDDLEWARE_CLASSES, and my ip is in the INTERNAL_IPS tuple. I have run the setup.py script and everything seems to load fine as I am getting no errors from django or apache.

However, nothing happens - no toolbar on any pages, has anyone else ever seen this behavior? Am I missing something obvious?

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

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

发布评论

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

评论(2

烟织青萝梦 2024-10-25 10:58:50

我有一段时间也遇到过同样的问题。

您是否尝试过登录管理面板?如果工具栏显示在那里,但未显示在您的代码中,则很可能您缺少模板中的开始和结束标记。默认情况下,django 调试工具栏附加到 BODY 标记,但您可以根据需要更改此行为。请参阅此问题:Django 调试工具栏仅适用于管理部分

I had this same issue for awhile.

Have you tried logging into the admin panel? If the toolbar displays there, but does not display in your code, it's very likely that you are missing the opening and closing tags in your template. By default, django debug toolbar attaches to the BODY tag, though you can change this behavior if you desire. See this question: Django Debug Toolbar Only Working for Admin Section

So要识趣 2024-10-25 10:58:50

我要么做两件事之一:

insert import pdb; pdb.set_trace() 在中间件 _show_toolbar 方法中,查看它在哪个项目上失败,或者在中间件中添加打印语句以查看它在哪个检查上失败,无论您更喜欢哪个和。

def _show_toolbar(self, request, response=None):
        if not settings.DEBUG or not getattr(settings, 'DEBUG_TOOLBAR', True) or getattr(settings, 'TEST', False):
            return False

        if request.path.startswith(settings.MEDIA_URL):
            return False

        if response:
            if getattr(response, 'skip_debug_response', False):
                return False
            if response.status_code >= 300 and response.status_code < 400:
                return False

        # Allow access if remote ip is in INTERNAL_IPS or
        # the user doing the request is logged in as super user.
        if (not request.META.get('REMOTE_ADDR') in settings.INTERNAL_IPS and 
           (not request.user.is_authenticated() or not request.user.is_superuser)):
            return False
        return True

I'd either do one of 2 things:

insert import pdb; pdb.set_trace() at the middleware _show_toolbar method and see which item it fails on, or pepper the middleware with print statements to see which check it failed on, whichever you're more comfortable with.

def _show_toolbar(self, request, response=None):
        if not settings.DEBUG or not getattr(settings, 'DEBUG_TOOLBAR', True) or getattr(settings, 'TEST', False):
            return False

        if request.path.startswith(settings.MEDIA_URL):
            return False

        if response:
            if getattr(response, 'skip_debug_response', False):
                return False
            if response.status_code >= 300 and response.status_code < 400:
                return False

        # Allow access if remote ip is in INTERNAL_IPS or
        # the user doing the request is logged in as super user.
        if (not request.META.get('REMOTE_ADDR') in settings.INTERNAL_IPS and 
           (not request.user.is_authenticated() or not request.user.is_superuser)):
            return False
        return True
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文