티스토리 뷰
장고를 사용하다 보면, 다음과 같은 에러를 볼 수 있다.
'Specifying a namespace in include() without providing an app_name
' django.core.exceptions.ImproperlyConfigured:
Specifying a namespace in include() without providing an app_name is not supported.
Set the app_name attribute in the included module, or pass a 2-tuple containing
the list of patterns and app_name instead.
'Specifying a namespace in include() without providing an app_name ' django.core.exceptions.ImproperlyConfigured: Specifying a namespace in include() without providing an app_name is not supported. Set the app_name attribute in the included module, or pass a 2-tuple containing the list of patterns and app_name instead
이는 include함수의 인자 문제로 혹시라도 사이트의 urls.py에
url(~~, include(r'^sample/', include('sample.urls', namespace='sample')) 과 같이
include 함수에 namepspace가 지정되는 경우, Django 2.0 이후에서는 컴파일 에러가 발생하게 된다.
또, url(r'^admin/' ,include(admin.site.urls)) 를 사용하는 경우에도 컴파일 에러를 발생시킬 수 있다. Django v2.0이후 버젼에선 url보다 path함수의 사용을 권장하고 있으며, 이 경우엔 path('admin/', admin.site.urls) 로 변경해주면 컴파일 에러가 사라진다.
사실, url의 include에 namepspace를 넣어줄 수 있는 방법은 Django 공식 문서에 쓰여있지만, 다른 방법을 이용하자면, Project 말고 Application의 urls.py에 app_name = 'blogs'같이 namespace 의 이름을 직접 지정해 주는 방법도 있다.
'개발 > Django Webapp' 카테고리의 다른 글
Django 공부하기 (0) | 2018.12.02 |
---|---|
국제 유학생들과 재학생 간 매칭 웹 어플리케이션 개발 예정 (0) | 2018.11.19 |