路由urls.py
from django.conf.urls import url from goods.views import IndexView, DetailView, ListView urlpatterns = [ url(r'^index$', IndexView.as_view(), name='index'), # 首页 url(r'^goods/(?P<goods_id>d+)$', DetailView.as_view(), name='detail'), # 详情页 url(r'^list/(?P<type_id>d+)/(?P<page>d+)$', ListView.as_view(), name='list'), # 列表页 多参数 ]
templates渲染页面中
<li><a href="{% url 'goods:detail' banner.sku.id %}"><img src="{{ banner.image.url }}" alt="幻灯片"></a></li> {# 单参数 #}
<li><a href="{% url 'goods:list' type.id pindex %}?sort={{ sort }}" class="active">{{ pindex }}</a></lid> {# 多参数 #}