
articles와 users에서 동일한 URL 패턴이 존재할 경우를 가정함.hello/ URL 패턴을 두 앱에서 모두 사용하기에, 해당 패턴을 사용할 때 어떤 앱의 패턴을 사용하는 것인지 혼란 발생.# articles/urls.py
urlpatterns = [
path("hello/", views.hello, name="hello"),
]
# users/urls.py
from django.urls import path
from . import views
urlpatterns = [
path("hello/", views.hello, name="hello"),
]
app_name을 설정해 네임스페이스를 적용.# articles/urls.py
from django.urls import path
from . import views
app_name = "articles" # 네임스페이스 = articles
urlpatterns = [
path("hello/", views.hello, name="hello"),
]
# users/urls.py
from django.urls import path
from . import views
app_name = "users" # 네임스페이스 = users
urlpatterns = [
path("hello/", views.hello, name="hello"),
]
namespace:url_name 형식을 사용함.{% url 'articles:hello' %} # articles 앱의 hello URL 참조
{% url 'users:hello' %} # users 앱의 hello URL 참조
redirect('articles:hello') # articles 앱의 hello URL로 리디렉션
redirect('users:hello') # users 앱의 hello URL로 리디렉션
{% url 'create' %} -> {% url 'articles:create' %}
redirect('create') -> redirect('articles:create')
NoReverseMatch: Django에서 URL을 역으로 매핑할 때 URL 패턴을 찾지 못할 경우 발생하는 오류.NoReverseMatch: Reverse for 'hello' not found. 'hello' is not a valid view function or pattern name.