### テンプレート側
/hello/templates/hello/index.html
<body>
<h1>{{title}}</h1>
<p>{{msg}}</p>
<p><a href="{% url goto %}">{{goto}}</a></p>
</body>
</html>
– {% %}はテンプレートタグ
– {% url ${name} %}で、urls.pyで指定しているnameのパスに遷移する
### views.py
/hello/views.py
def index(request):
params = {
'title':'Hello/Index',
'msg':'this is sample page.',
'goto':'next',
}
return render(request, 'hello/index.html', params)
def next(request):
params = {
'title':'Hello/Index',
'msg':'this is another page.',
'goto':'index',
}
return render(request, 'hello/index.html', params)
### urls.py
/hello/urls.py
urlpatterns = [
path('', views.index, name='index'),
path('next', views.next, name='next'),
]
http://192.168.33.10:8000/hello/

http://192.168.33.10:8000/hello/next

{% %}のテンプレートタグがやや特殊な動きをします。