3.6 Add namespace for URL
parent
aae69f930b
commit
624f61a563
|
@ -240,3 +240,10 @@ Consider `index.html` will be reused numerous times, 去耦合is necessary.
|
|||
```html
|
||||
<li><a href="{% url 'detail' question.id %}">{{ question.question_text }}</a></li>
|
||||
```
|
||||
|
||||
### 3.6 为 URL 名称添加命名空间
|
||||
|
||||
在根 URLconf 中添加命名空间 (namespace)
|
||||
|
||||
1. Add `app_name = 'polls'` for namespace in `poll.urls.py`
|
||||
2. Change `detail` in `index.html` to `polls:detail`
|
|
@ -1,7 +1,7 @@
|
|||
{% if latest_question_list %}
|
||||
<ul>
|
||||
{% for question in latest_question_list %}
|
||||
<li><a href="{% url 'detail' question.id %}">{{ question.question_text }}</a></li>
|
||||
<li><a href="{% url 'polls:detail' question.id %}">{{ question.question_text }}</a></li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% else %}
|
||||
|
|
|
@ -2,6 +2,7 @@ from django.urls import path
|
|||
|
||||
from . import views
|
||||
|
||||
app_name = 'polls'
|
||||
urlpatterns = [
|
||||
# ex: /polls/
|
||||
path('', views.index, name='index'),
|
||||
|
|
Loading…
Reference in New Issue