티스토리 뷰

장고를 사용하다 보면, 다음과 같은 에러를 볼 수 있다.

'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 이후에서는 컴파일 에러가 발생하게 된다.

따라서 namespace 파라미터를 삭제한 후 include(r'^sample/', include('sample.urls')) 로만 함수를 작성한다면 컴파일 에러가 사라진다.

 

또, 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 의 이름을 직접 지정해 주는 방법도 있다.

댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
TAG
more
«   2024/04   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
글 보관함