<path_converter:variable_name>
urlpatterns = [
path('articles/1/', ...),
path('articles/2/', ...),
path('articles/3/', ...),
...,
]urlpatterns = [
path('articles/<int:num>/', ...),
]<int:num>, <str:name>의 위치에 들어있는 값이 변수처럼 취급됨views.detail에, 문자열 name 변수가 views.greeting에 키워드 인자로 전달됨/articles/10/ 이면, views.detail(request, num=10)의 형태로 호출urlpatterns = [
path('articles/<int:num>/', views.detail),
]def detail(request, num):
context = {
'num': num,
}
return render(request, 'articles/detail.html', context){% extends 'articles/base.html' %}
{% block content}
<h1>Detail</h1>
<h3>{{ num }}번 글 입니다.</h3>
{% endblock content %}
각 앱의 urls.py에서 각자의 URL 관리
App URL mapping이란, 각 앱에 URL을 정의하는 것
include 함수
include('app.urls')from django.urls import path
from . import views
urlpatterns = [
path('index/', views.index),
]include()로 추가from django.urls import path, include
urlpatterns = [
path('articles/', include('articles.urls')),
]from django.urls import path
from . import views
urlpatterns = [
path('index/', views.index, name='index'),
]# 전
{% extends 'articles/base.html' %}
{% block content}
<h1>Hello, {{ name }}</h1>
<a href="/dinner/">dinner</a>
<a href="/search/">search</a>
<a href="/throw/">throw</a>
{% endblock content %}# 후
{% extends 'articles/base.html' %}
{% block content}
<h1>Hello, {{ name }}</h1>
<a href="{% url 'dinner' %}">dinner</a>
<a href="{% url 'search' %}">search</a>
<a href="{% url 'throw' %}">throw</a>
{% endblock content %}{% url 'url_name' arg1 arg2 %}
url tag{% extends 'articles/base.html' %}
{% block content}
<h1>Articles</h1>
<a href="{% url 'detail' 1 %}">Article 1</a>
<a href="{% url 'detail' 2 %}">Article 2</a>
<a href="{% url 'detail' 3 %}">Article 3</a>
{% endblock content %}{% for num in nums %}
<a href="{% url 'detail' num %}">Article {{ num }}</a>
{% endfor %}app_name = 'articles'
urlpatterns = [
path('index/', views.index, name='index'),
]app_name = 'pages'
urlpatterns = [
path('index/', views.index, name='index'),
]{% url 'app_name:path_name' arg1 arg2 %}