장고 디버그 툴바가 표시되지 않음
다른 질문을 보았는데 이해할 수 없습니다 ...
django-debug-toolbar를 설치하기 위해 다음을 수행했습니다.
- pip 설치 django-debug-toolbar
- 미들웨어 클래스에 추가됨 :
MIDDLEWARE_CLASSES = ( 'django.middleware.common.CommonMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', # Uncomment the next line for simple clickjacking protection: # 'django.middleware.clickjacking.XFrameOptionsMiddleware', 'debug_toolbar.middleware.DebugToolbarMiddleware', )
3 INTERNAL_IPS 추가 :
INTERNAL_IPS = ( '174.121.34.187',)
4 설치된 앱에 debug_toolbar 추가
오류가 발생하지 않았으며 관리자가 아닌 모든 페이지에 툴바가 표시되지 않습니다.
심지어 debug_toolbar 템플릿의 디렉토리를 내 디렉토리에 추가했습니다. TEMPLATE_DIRS
멍청한 질문이지만, 당신은 그것을 언급하지 않았습니다. 그래서 ... 무엇으로 DEBUG
설정되어 있습니까? 이 아닌 경우로드되지 않습니다 True
.
여전히 작동하지 않으면 '127.0.0.1'도 추가하십시오 INTERNAL_IPS
.
최신 정보
이것은 당신이하지 말아야 최후의 필사적 인 노력의 움직임이다 가 이 일을하지만, 분명히 단지 일부 구성 문제가 있는지 표시하거나 약간 더 큰 문제가 있는지 여부 것입니다.
settings.py에 다음을 추가하십시오.
def show_toolbar(request):
return True
SHOW_TOOLBAR_CALLBACK = show_toolbar
디버그 툴바로 모든 검사를 효과적으로 제거하여 자체로드 해야하는지 여부를 결정합니다. 항상로드됩니다. 테스트 목적으로 만 남겨두고 잊어 버린 경우 모든 방문자가 디버그 도구 모음을 볼 수 있습니다.
명시 적 구성에 대해서는 공식 설치 문서를 참조 하십시오 .
편집 (2015 년 6 월 17 일) :
핵 옵션에 대한 구문이 변경되었습니다. 이제 자체 사전에 있습니다.
def show_toolbar(request):
return True
DEBUG_TOOLBAR_CONFIG = {
"SHOW_TOOLBAR_CALLBACK" : show_toolbar,
}
그들의 테스트 는이 사전을 사용합니다.
디버그 툴바는 request.META [ 'REMOTE_ADDR']의 IP 주소가 INTERNAL_IPS 설정에서 설정되기를 원합니다. 다음과 같은 견해 중 하나에서 인쇄 진술서를 던져보십시오.
print("IP Address for debug-toolbar: " + request.META['REMOTE_ADDR'])
그런 다음 해당 페이지를로드하십시오. settings.py의 INTERNAL_IPS 설정에 IP가 있는지 확인하십시오.
일반적으로 컴퓨터의 IP 주소를 확인하여 쉽게 주소를 결정할 수 있다고 생각하지만 포트 전달을 사용하여 가상 상자에서 서버를 실행하고 있으며 누가 무슨 일이 있었는지 알고 있습니다. VB 또는 내 자체 OS의 ifconfig에서 아무 것도 볼 수 없지만 REMOTE_ADDR 키에 표시된 IP는 툴바를 활성화하는 트릭이었습니다.
다른 모든 것이 괜찮다면 템플릿에 명시적인 닫기 <body>
태그 가없는 것일 수도 있습니다.
참고 : 디버그 도구 모음은 응답의 MIME 유형이 text / html 또는 application / xhtml + xml이고 닫는 태그가있는 경우에만 표시됩니다.
현재 안정 버전 0.11.0에서는 툴바가 표시 되려면 다음 사항이 충족되어야합니다.
설정 파일 :
DEBUG = True
INTERNAL_IPS
서버 주소가 아닌 브라우저 IP 주소를 포함합니다. 로컬 검색하면이 있어야한다INTERNAL_IPS = ('127.0.0.1',)
. 원격으로 탐색하는 경우 공개 주소 만 지정하십시오 .- 설치 될 debug_toolbar 앱
INSTALLED_APPS = (..., 'debug_toolbar',)
- 추가 될 디버그 도구 모음 미들웨어 클래스
MIDDLEWARE_CLASSES = ('debug_toolbar.middleware.DebugToolbarMiddleware', ...)
. 목록에 가능한 빨리 배치해야합니다.
템플릿 파일 :
- 유형이어야합니다
text/html
- 닫기
</html>
태그 가 있어야합니다
정적 파일 :
정적 컨텐츠를 제공하는 경우 다음을 수행하여 CSS, js 및 html을 수집하십시오.
./manage.py collectstatic
곧 출시 될 django-debug-toolbar 버전에 대한 참고 사항
최신 개발 버전에는 설정 지점 2, 3 및 4에 대한 기본값이 추가되었으므로 개발 버전과 마찬가지로 버그가있는 삶을 조금 더 간단하게 만듭니다. ImproperlyConfigured
nginx / uwsgi를 통해 실행할 때 git의 최신 버전에서 오류가 발생했습니다.
어느 쪽이든, github run에서 최신 버전을 설치하려면 다음을 수행하십시오.
pip install -e git+https://github.com/django-debug-toolbar/django-debug-toolbar.git#egg=django-debug-toolbar
다음을 수행하여 특정 커밋을 복제 할 수도 있습니다.
pip install -e git+https://github.com/django-debug-toolbar/django-debug-toolbar.git@ba5af8f6fe7836eef0a0c85dd1e6d7418bc87f75#egg=django_debug_toolbar
DEBUG = True
설정 INTERNAL_IPS
에서 클라이언트의 IP 주소, Django Debug Toolbar 수동 구성 까지 모든 것을 시도했습니다 (최신 버전은 미들웨어 및 URL 추가와 같은 모든 구성을 자동으로 수행합니다). 원격 개발 서버에서는 아무것도 작동하지 않았습니다 (로컬에서는 작동했지만). 작동하는 유일한 것은 툴바를 다음과 같이 구성하는 것입니다.
DEBUG_TOOLBAR_CONFIG = {
"SHOW_TOOLBAR_CALLBACK" : lambda request: True,
}
도구 모음을 표시 할지를 결정하는 기본 방법을 대체하고 항상 true를 반환합니다.
툴바가 완벽하게 작동합니다. 이 구성으로 :
DEBUG = True
INTERNAL_IPS = ('127.0.0.1', '192.168.0.1',)
DEBUG_TOOLBAR_CONFIG = {'INTERCEPT_REDIRECTS': False,}
- 미들웨어는 다음의 첫 번째 요소입니다
MIDDLEWARE_CLASSES
.
MIDDLEWARE_CLASSES = ( 'debug_toolbar.middleware.DebugToolbarMiddleware', 'django.middleware.common.CommonMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', )
나는 그것이 도움이되기를 바랍니다
10.0.2.2
Windows의 INTERNAL_IPS에 추가 하면 내부적으로 방랑자와 함께 사용됩니다.
INTERNAL_IPS = ('10 .0.2.2 ',)
이 작동합니다.
도커
If you're developing with a Django server in a Docker container with docker, the instructions for enabling the toolbar don't work. The reason is related to the fact that the actual address that you would need to add to INTERNAL_IPS
is going to be something dynamic, like 172.24.0.1. Rather than trying to dynamically set the value of INTERNAL_IPS
, the straightforward solution is to replace the function that enables the toolbar, in your settings.py
, for example:
DEBUG_TOOLBAR_CONFIG = {
'SHOW_TOOLBAR_CALLBACK': lambda _request: DEBUG
}
This should also work for other dynamic routing situations, like vagrant.
Here are some more details for the curious. The code in django_debug_tool that determines whether to show the toolbar examines the value of REMOTE_ADDR
like this:
if request.META.get('REMOTE_ADDR', None) not in INTERNAL_IPS:
return False
so if you don't actually know the value of REMOTE_ADDR
due to your dynamic docker routing, the toolbar will not work. You can use the docker network command to see the dynamic IP values, for example docker network inspect my_docker_network_name
I had the same problem and finally resolved it after some googling.
In INTERNAL_IPS, you need to have the client's IP address.
Another thing that can cause the toolbar to remain hidden is if it cannot find the required static files. The debug_toolbar templates use the {{ STATIC_URL }} template tag, so make sure there is a folder in your static files called debug toolbar.
The collectstatic management command should take care of this on most installations.
I tried the configuration from pydanny's cookiecutter-django and it worked for me:
# django-debug-toolbar
MIDDLEWARE_CLASSES = Common.MIDDLEWARE_CLASSES + ('debug_toolbar.middleware.DebugToolbarMiddleware',)
INSTALLED_APPS += ('debug_toolbar',)
INTERNAL_IPS = ('127.0.0.1',)
DEBUG_TOOLBAR_CONFIG = {
'DISABLE_PANELS': [
'debug_toolbar.panels.redirects.RedirectsPanel',
],
'SHOW_TEMPLATE_CONTEXT': True,
}
# end django-debug-toolbar
I just modified it by adding 'debug_toolbar.apps.DebugToolbarConfig'
instead of 'debug_toolbar'
as mentioned in the official django-debug-toolbar docs, as I'm using Django 1.7.
An addition to previous answers:
if the toolbar doesn't show up, but it loads in the html (check your site html in a browser, scroll down)
the issue can be that debug toolbar static files are not found (you can also see this in your site's access logs then, e.g. 404 errors for /static/debug_toolbar/js/toolbar.js)
It can be fixed the following way then (examples for nginx and apache):
nginx config:
location ~* ^/static/debug_toolbar/.+.(ico|css|js)$ {
root [path to your python site-packages here]/site-packages/debug_toolbar;
}
apache config:
Alias /static/debug_toolbar [path to your python site-packages here]/site-packages/debug_toolbar/static/debug_toolbar
Or:
manage.py collectstatic
more on collectstatic here: https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/#collectstatic
Or manualy move debug_toolbar folder of debug_toolbar static files to your set static files folder
django 1.8.5:
I had to add the following to the project url.py file to get the debug toolbar display. After that debug tool bar is displayed.
from django.conf.urls import include
from django.conf.urls import patterns
from django.conf import settings
if settings.DEBUG:
import debug_toolbar
urlpatterns += patterns('',
url(r'^__debug__/', include(debug_toolbar.urls)),
)
django 1.10: and higher:
from django.conf.urls import include, url
from django.conf.urls import patterns
from django.conf import settings
if settings.DEBUG:
import debug_toolbar
urlpatterns =[
url(r'^__debug__/', include(debug_toolbar.urls)),
] + urlpatterns
Also don't forget to include the debug_toolbar to your middleware. The Debug Toolbar is mostly implemented in a middleware. Enable it in your settings module as follows: (django newer versions)
MIDDLEWARE = [
# ...
'debug_toolbar.middleware.DebugToolbarMiddleware',
#
Old-style middleware:(need to have _CLASSES keywork in the Middleware)
MIDDLEWARE_CLASSES = [
# ...
'debug_toolbar.middleware.DebugToolbarMiddleware',
# ...
]
This wasn't the case for this specific author but I just have been struggling with the Debug Toolbar not showing and after doing everything they pointed out, I found out it was a problem with MIDDLEWARE order. So putting the middleware early in the list could work. Mine is first:
MIDDLEWARE_CLASSES = ( 'debug_toolbar.middleware.DebugToolbarMiddleware', 'django.middleware.common.CommonMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'dynpages.middleware.DynpageFallbackMiddleware', 'utils.middleware.UserThread', )
In my case, it was another problem that hasn't been mentioned here yet: I had GZipMiddleware in my list of middlewares.
As the automatic configuration of debug toolbar puts the debug toolbar's middleware at the top, it only gets the "see" the gzipped HTML, to which it can't add the toolbar.
I removed GZipMiddleware in my development settings. Setting up the debug toolbar's configuration manually and placing the middleware after GZip's should also work.
In my case I just needed to remove the python compiled files (*.pyc
)
you have to make sure there is a closing tag in your templates.
My problem is that there is no regular html tags in my templates, I just display content in plain text. I solved it by inheriting every html file from base.html, which has a tag.
For me this was as simple as typing 127.0.0.1:8000
into the address bar, rather than localhost:8000
which apparently was not matching the INTERNAL_IPS.
I got the same problem, I solved it by looking at the Apache's error log. I got the apache running on mac os x with mod_wsgi The debug_toolbar's tamplete folder wasn't being load
Log sample:
==> /private/var/log/apache2/dummy-host2.example.com-error_log <==
[Sun Apr 27 23:23:48 2014] [error] [client 127.0.0.1] File does not exist: /Library/WebServer/Documents/rblreport/rbl/static/debug_toolbar, referer: http://127.0.0.1/
==> /private/var/log/apache2/dummy-host2.example.com-access_log <==
127.0.0.1 - - [27/Apr/2014:23:23:48 -0300] "GET /static/debug_toolbar/css/toolbar.css HTTP/1.1" 404 234 "http://127.0.0.1/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:28.0) Gecko/20100101 Firefox/28.0"
I just add this line to my VirtualHost file:
Alias /static/debug_toolbar /Library/Python/2.7/site-packages/debug_toolbar/static/debug_toolbar
- Of course you must change your python path
I had the same problem using Vagrant. I solved this problem by adding ::ffff:192.168.33.1
to the INTERNAL_IPS as below example.
INTERNAL_IPS = (
'::ffff:192.168.33.1',
)
Remembering that 192.168.33.10
is the IP in my private network in Vagrantfile.
I had this problem and had to install the debug toolbar from source.
Version 1.4 has a problem where it's hidden if you use PureCSS and apparently other CSS frameworks.
This is the commit which fixes that.
The docs explain how to install from source.
For anyone who is using Pycharm 5 - template debug is not working there in some versions. Fixed in 5.0.4, affected vesions - 5.0.1, 5.0.2 Check out issue
Spend A LOT time to find that out. Maybe will help someone
In the code I was working on, multiple small requests were made during handling of main request (it's very specific use case). They were requests handled by the same Django's thread. Django debug toolbar (DjDT) doesn't expect this behaviour and includes DjDT's toolbars to the first response and then it removes its state for the thread. So when main request was sent back to the browser, DjDT was not included in the response.
Lessons learned: DjDT saves it's state per thread. It removes state for a thread after the first response.
What got me is an outdated browser!
Noticed that it loads some stylesheets from debug toolbar and guessed it might be a front-end issue.
One stupid thing got me.. that if you use apache wsgi, remember to touch the .wsgi file to force your code recompile. just waste 20 minutes of my time to debug the stupid error :(
참고URL : https://stackoverflow.com/questions/10517765/django-debug-toolbar-not-showing-up
'development' 카테고리의 다른 글
뮤텍스와 크리티컬 섹션의 차이점은 무엇입니까? (0) | 2020.07.02 |
---|---|
nginx가 반환 한 서버 헤더를 어떻게 변경합니까? (0) | 2020.07.02 |
현재 시간이 시간 범위에 속하는지 확인 (0) | 2020.07.02 |
git rebase --onto의 동작을 이해할 수 없습니다 (0) | 2020.07.02 |
iPhone 5 CSS 미디어 쿼리 (0) | 2020.07.02 |