调试工具栏未显示

发布于 2025-01-26 22:17:57 字数 465 浏览 3 评论 0原文

  • 我安装了:pip安装django-debug-toolbar,
  • 我的设置中有debug = true
  • 我有django.contrib.contrib.staticfiles和debug_toolbar in installed_apps
  • 有static_url ='/static/'
  • 我 在Middleware_classes中,
  • 我有internal_ips = ['127.0.0.1']在我的设置中,
  • 我有urlpatterns = [
    ...
    路径(' debug /',包括(debug_toolbar.urls))
    这是给出的
    并在项目的urlconfig中导入debug_toolbar。
  • 我运行了python manage.py collectstatic和debug工具栏未显示在我的浏览器中
    我该如何修复?
  • I installed: pip install django-debug-toolbar
  • I have DEBUG=True in my settings
  • I have django.contrib.staticfiles and debug_toolbar in INSTALLED_APPS
  • i have STATIC_URL = '/static/' in STATIC_URL
  • I have 'debug_toolbar.middleware.DebugToolbarMiddleware' high up in MIDDLEWARE_CLASSES
  • I have INTERNAL_IPS = ['127.0.0.1'] in my settings
  • I have urlpatterns = [
    ...
    path('debug/', include(debug_toolbar.urls))
    ]
    and Import debug_toolbar in URLConfig of project.
  • I have run python manage.py collectstatic and Debug Toolbar not showing in my browser
    How can I fix it?

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

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

发布评论

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

评论(2

横笛休吹塞上声 2025-02-02 22:17:57

中加入了此设置。

您是否在settings.py #settings.py

DEBUG_TOOLBAR_CONFIG = {
    "DISABLE_PANELS": ["debug_toolbar.panels.redirects.RedirectsPanel"],
    "SHOW_TEMPLATE_CONTEXT": True,
    "SHOW_TOOLBAR_CALLBACK": "app_name.small_utils.show_toolbar_callback", # this is the location of the function show_toolbar_callback
}

#app_name/small_utils.py

def show_toolbar_callback(request):
    return not request.is_ajax() and request.user and request.user.is_superuser

设置此设置后,您的调试工具栏将开始工作。

Have you included this setting in settings.py

#settings.py

DEBUG_TOOLBAR_CONFIG = {
    "DISABLE_PANELS": ["debug_toolbar.panels.redirects.RedirectsPanel"],
    "SHOW_TEMPLATE_CONTEXT": True,
    "SHOW_TOOLBAR_CALLBACK": "app_name.small_utils.show_toolbar_callback", # this is the location of the function show_toolbar_callback
}

#app_name/small_utils.py

def show_toolbar_callback(request):
    return not request.is_ajax() and request.user and request.user.is_superuser

After setting this your debug toolbar will start working.

秋叶绚丽 2025-02-02 22:17:57

测试它是否在管理区域上工作的视图模板HTML代码应有效的样板。
例如,调试栏显示此页面,

<html lang="en">
  <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>HTML 5 Boilerplate</title>
  </head>
  <body>
      <form action="{% url 'polls:vote' question.id %}" method="post">
{% csrf_token %}
<fieldset>
    <legend><h1>{{ question.question_text }}</h1></legend>
    {% if error_message %}<p><strong>{{ error_message }}</strong></p>{% endif %}
    {% for choice in question.choice_set.all %}
        <input type="radio" name="choice" id="choice{{ forloop.counter }}" value="{{ choice.id }}">
        <label for="choice{{ forloop.counter }}">{{ choice.choice_text }}</label><br>
    {% endfor %}
</fieldset>
<input type="submit" value="Vote">
</form>

  </body>
</html>

但对于此HTML模板,它不起作用:

  <form action="{% url 'polls:vote' question.id %}" method="post">
{% csrf_token %}
<fieldset>
    <legend><h1>{{ question.question_text }}</h1></legend>
    {% if error_message %}<p><strong>{{ error_message }}</strong></p>{% endif %}
    {% for choice in question.choice_set.all %}
        <input type="radio" name="choice" id="choice{{ forloop.counter }}" value="{{ choice.id }}">
        <label for="choice{{ forloop.counter }}">{{ choice.choice_text }}</label><br>
    {% endfor %}
</fieldset>
<input type="submit" value="Vote">
</form>

Test whether it works on admin area The view template html code on frontend should be valid boilerplate.
For example debug bar shows for this page

<html lang="en">
  <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>HTML 5 Boilerplate</title>
  </head>
  <body>
      <form action="{% url 'polls:vote' question.id %}" method="post">
{% csrf_token %}
<fieldset>
    <legend><h1>{{ question.question_text }}</h1></legend>
    {% if error_message %}<p><strong>{{ error_message }}</strong></p>{% endif %}
    {% for choice in question.choice_set.all %}
        <input type="radio" name="choice" id="choice{{ forloop.counter }}" value="{{ choice.id }}">
        <label for="choice{{ forloop.counter }}">{{ choice.choice_text }}</label><br>
    {% endfor %}
</fieldset>
<input type="submit" value="Vote">
</form>

  </body>
</html>

But for this html template it doesn't work:

  <form action="{% url 'polls:vote' question.id %}" method="post">
{% csrf_token %}
<fieldset>
    <legend><h1>{{ question.question_text }}</h1></legend>
    {% if error_message %}<p><strong>{{ error_message }}</strong></p>{% endif %}
    {% for choice in question.choice_set.all %}
        <input type="radio" name="choice" id="choice{{ forloop.counter }}" value="{{ choice.id }}">
        <label for="choice{{ forloop.counter }}">{{ choice.choice_text }}</label><br>
    {% endfor %}
</fieldset>
<input type="submit" value="Vote">
</form>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文