Django로 개발할 때 유용한 Tool인 Django Debug Toolbar를 설치하는 방법에 대해서 적어보려고 한다. 

문서의 내용은 Django에서 설치하는 방법이지만 현재 Wagtail을 사용하고 있기 때문에 Wagtail에서 사용하는 방법에 대해서 정리하려고 한다. 

 

Django에서 적용하고 싶은 사람은 공식 문서를 따라하면 될 것이다.

https://django-debug-toolbar.readthedocs.io/en/latest/installation.html

 

Installation — Django Debug Toolbar 3.2.2 documentation

Each of the following steps needs to be configured for the Debug Toolbar to be fully functional. Troubleshooting On some platforms, the Django runserver command may use incorrect content types for static assets. To guess content types, Django relies on the

django-debug-toolbar.readthedocs.io

 

 

1. Django Debug Toolbar 설치

python -m pip install django-debug-toolbar

 

 

2. Module 적용

wagtail settings에는 base.py, dev.py, production.py가 있다. 

 

1)base.py

This file is for global settings that will be used in both development and production. Aim to keep most of your configuration in this file.

 

2)dev.py

This file is for settings that will only be used by developers. For example: DEBUG = True

 

3)production.py

This file is for settings that will only run on a production server. For example: DEBUG = False

 

4)local.py

This file is used for settings local to a particular machine. This file should never be tracked by a version control system.

 

1) base.py 는 공통적으로 사용하는 것을 정의 해 놓는다.

2) dev.py에는 로컬 단계. 즉 개발할 때 사용하는 것을 정의 해 놓는다.

3) production.py는 배포 서버를 위해 사용하는 것을 정의한다.

4) local.py 특정 기기에서 사용할 것을 정의한다. 

 

my_project/settings/dev.py

INSTALLED_APPS = INSTALLED_APPS + [
    'debug_toolbar',
]

INTERNAL_IPS = [
    '127.0.0.1',
]

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

형식은 위와 같이 '+' 로 추가해준다고 적어주면 된다. 

 

INTERNAL_IPS는 로컬에서만 Debug Toolbar를 사용할 것이기 때문에 로컬 주소를 적어준다. 

 

MIDDLEWARE도 마찬가지로 dev.py에서 추가로 관리할 수 있다. 

 

 

3. URL 설정

my_project/urls.py

if settings.DEBUG:
    from django.conf.urls.static import static
    from django.contrib.staticfiles.urls import staticfiles_urlpatterns

    # Serve static and media files from development server
    urlpatterns += staticfiles_urlpatterns()
    urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
    
    import debug_toolbar
    
    urlpatterns = urlpatterns + [
        path('__debug__/', include(debug_toolbar.urls)),
    ]

Debug 세팅을 위해 위와 같이 수정해준다. 역시나 마찬가지로 추가적인 설정이 있으면 '+'를 통해 종류별로 구별해서 정리할 수 있다. 

 

'__debug__'는 debug toolbar의 주소이다. (다른 App이랑 충돌이 안나는 선에서 아무거나 입력해도 된다. debug_toobar.urls만 명시해주면 된다. )

 

 

 

 

4. 적용 확인

python manage.py runserver

서버를 실행하고 웹 페이지에 들어가보면 적용이 되어 있는 것을 확인할 수 있다. Debug Toolbar를 통해 개발하는데 구체적인 정보를 얻을 수 있다. 

'Back-End > Wagtail, Django' 카테고리의 다른 글

Wagtail Routable Pages  (0) 2021.11.16
Wagtail BaseSetting  (0) 2021.11.15
Django, Wagtail Vue 로그인 연동  (0) 2021.11.12
Wagtail Rich Editor 기능 추가  (0) 2021.11.06
Wagtail Admin Page 한글 설정  (0) 2021.11.04

+ Recent posts