3.4 Remove hardlink URL in template
parent
f91a6b6e25
commit
aae69f930b
|
@ -224,3 +224,19 @@ Here `path()` function is passed **route** and **view**; two additional option a
|
|||
```
|
||||
|
||||
模板系统统一使用点符号来访问变量的属性
|
||||
|
||||
### 3.5 Remove hardlink URL in template
|
||||
|
||||
In template `polls/index.html`, links are hardcoded as shown
|
||||
|
||||
```html
|
||||
{% for question in latest_question_list %}
|
||||
<li><a href="/polls/{{ question.id }}/">{{ question.question_text }}</a></li>
|
||||
{% endfor %}
|
||||
```
|
||||
|
||||
Consider `index.html` will be reused numerous times, 去耦合is necessary.
|
||||
|
||||
```html
|
||||
<li><a href="{% url 'detail' question.id %}">{{ question.question_text }}</a></li>
|
||||
```
|
|
@ -1,7 +1,7 @@
|
|||
{% if latest_question_list %}
|
||||
<ul>
|
||||
{% for question in latest_question_list %}
|
||||
<li><a href="/polls/{{ question.id }}/">{{ question.question_text }}</a></li>
|
||||
<li><a href="{% url 'detail' question.id %}">{{ question.question_text }}</a></li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% else %}
|
||||
|
|
Loading…
Reference in New Issue