파이썬 2.7.11 및 django 1.10.2를 사용합니다. 나는 URL을 생성하고 동적으로 템플릿을 사용합니다.템플릿에 동적 URL을 사용하는 방법
urls.py
url(r'^suits-anarkali/', include([
url(r'^$', category_page, name="suits-anarkali"),
url(r'^(?P<slug>[\w-]+)/$', category_page, name="suits-anarkali"),
url(r'^(?P<slug>[\w-]+)/$', single_product, name='singleproduct'),
url(r'^(?P<slug>[\w-]+)/(?P<singleproduct_slug>[\w-]+)/$', singleproduct, name="singleproduct"),
])
),
이 내 URL 구조입니다. 슬러그로 category_page를 호출하면 제대로 작동하지만 슬러그로 single_product를 호출하면 카테고리 페이지로 리디렉션됩니다. 많은 시간을 보았지만 작동하지 않습니다. 그래서 어떻게 템플릿에 대한 URL을 관리 할 수 있습니까?
product.html
{% if slug %}
<a href="{% url 'singleproduct' slug detail.slug %}">{{ detail.product_name }}</a>
{% else %}
<a href="{% url 'singleproduct' detail.slug %}">{{ detail.product_name }}</a>
{% endif %}
URL이 첫 경기의 정규 표현식으로 작동, 당신은 슬러그와 URL을 호출 할 때 일치하는 아래 두 줄 때문에 정확히 같은 슬러그 매개 변수, 그것은
category_page
입니다
요청하기 전에 우리의 철자를 확인하시기 바랍니다. 나는 2 개의 오타를 바로 잡았다. – guettli