django debug toolbar使用简介,及docker中使用

Installation

Getting the code

The recommended way to install the Debug Toolbar is via pip:

$ pip install django-debug-toolbar

If you aren’t familiar with pip, you may also obtain a copy of thedebug_toolbar directory and add it to your Python path.

To test an upcoming release, you can install the in-development versioninstead with the following command:

$ pip install -e git+https://github.com/jazzband/django-debug-toolbar.git#egg=django-debug-toolbar

Prerequisites

Make sure that 'django.contrib.staticfiles' is set up properly and add'debug_toolbar' to your INSTALLED_APPS setting:

INSTALLED_APPS = [
    # ...
    'django.contrib.staticfiles',
    # ...
    'debug_toolbar',
]

STATIC_URL = '/static/'

If you’re upgrading from a previous version, you should review thechange log and look for specific upgrade instructions.

URLconf

Add the Debug Toolbar’s URLs to your project’s URLconf as follows:

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

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

This example uses the __debug__ prefix, but you can use any prefix thatdoesn’t clash with your application’s URLs. Note the lack of quotes arounddebug_toolbar.urls.

Middleware

The Debug Toolbar is mostly implemented in a middleware. Enable it in yoursettings module as follows:

MIDDLEWARE = [
    # ...
    'debug_toolbar.middleware.DebugToolbarMiddleware',
    # ...
]

Old-style middleware:

MIDDLEWARE_CLASSES = [
    # ...
    'debug_toolbar.middleware.DebugToolbarMiddleware',
    # ...
]

Warning

The order of MIDDLEWARE and MIDDLEWARE_CLASSES is important. Youshould include the Debug Toolbar middleware as early as possible in thelist. However, it must come after any other middleware that encodes theresponse’s content, such asGZipMiddleware.

Internal IPs

The Debug Toolbar is shown only if your IP is listed in the INTERNAL_IPSsetting. (You can change this logic with the SHOW_TOOLBAR_CALLBACKoption.) For local development, you should add '127.0.0.1' toINTERNAL_IPS.


USE IN DOCKER :


IP address that allowed me to display django toolbar was the IP of the getway associated with my docker container. To obtain IP of the gatway I run this comand

docker inspect my_container_name | grep -e '"Gateway"'
# "Gateway": "172.18.0.1",

In total my settings look like this

INSTALLED_APPS = (
    'debug_toolbar',
)
INTERNAL_IPS = ['172.18.0.1']



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值