在Django中,当我单击返回ID的链接,但页面未显示为返回时。
这是网址,
url(r'^(?P<pk>[-\w]+)/$', views.SchoolDetailView.as_view(),name = 'detail')
View.py
class SchoolDetailView(DetailView):
context_object_name = 'school_detail'
model = models.School
template_name = 'basic_app/school_detail.html'
HTML视图
{% for school in schools %}
<h2><li><a href="{{school.id}}">{{school.name}}</a></li></h2>
{% endfor %}
答案 0 :(得分:0)
您需要按以下方式调用detail
视图:
{% for school in schools %}
<h2><li><a href="{% url "detail" school.id %}">{{school.name}}</a></li></h2>
{% endfor %}
答案 1 :(得分:0)
使用{% url %}模板标记在模板中提供网址
<a href="{% url 'detail' school.id %}">{{school.name}}</a>