没有模板渲染,url表达式正则表达式

时间:2017-04-04 18:48:02

标签: regex django url

Imagem error look here模板的HTML

  <p>
   <a href="{% url 'courses:enrollment' courses.slug % }" class="pure-buttonprimary-button">Inscreva-se</a>
   </p>

URLS.py

    urlpatterns = [

    url(r'^$', index, name = 'index'),
    #url(r'^(?P<pk>\d+)/$', details, name = 'details'),
    url(r'^(?P<slug>[\w_-]+)/$', details, name = 'details'),
    url(r'^(?P<slug>[\w_-]+)/inscricao/$', enrollment, name = 'enrollment'),

]

Url找不到指定的路径。

2 个答案:

答案 0 :(得分:2)

标记末尾的%}之间有空格。

{% url 'courses:enrollment' courses.slug % }
                                          ^

将其更改为

{% url 'courses:enrollment' courses.slug %}

由于您在标记courses中使用了名称空间courses:enrollment,因此应在app_name文件中设置courses/urls.py

app_name = 'courses'
urlpatterns = [
    ...
]

答案 1 :(得分:0)

您在网址反转中使用“课程”一词,即使它从未定义过。请尝试使用此功能:| OrderID | DateOrdered | EnteredById | OtherData | OtherData2 | ----------------------------------------------------------------------- | 1 | 2/2/2017 | 3 | asdf | sadfsf | | 2 | 2/2/2017 | 4 | asdf | sadfsf | | 3 | 2/3/2017 | 4 | asdf | sadfsf | | 4 | 2/4/2017 | 3 | asdf | sadfsf | | 5 | 2/4/2017 | 4 | asdf | sadfsf | | 6 | 2/6/2017 | 5 | asdf | sadfsf |