我正在尝试制作我的第一个Django应用程序,但在第二个URL上仍然看到“语法无效”错误:
urlpatterns = [
url(r'^$',views.index, name='index')
url(r'^details/(?P<id>\d+)/$',views.details, name ='details')
];
为什么会这样?
答案 0 :(得分:1)
由于<div *ngFor="let news of data.articles">
<h3>{{news.author}}</h3>
</div>
是urlpatterns
,因此您需要用“,”分隔每个项目,您的正确代码是
list
如果要创建urlpatterns = [
url(r'^$',views.index, name='index'),
url(r'^details/(?P<id>\d+)/$', views.details, name ='details')
];
答案 1 :(得分:0)
urlpatterns
是list
,并且list
的值必须用逗号分隔。
urlpatterns = [
url(r'^$',views.index, name='index'),
url(r'^details/(?P<id>\d+)/$',views.details, name ='details')
]
答案 2 :(得分:0)
Django urlpatterns是您要用,
分隔的列表中的列表,因此您需要在每个项目之后添加,
我只是为您编码,请尝试以下操作:
urlpatterns = [
url(r'^$',views.index, name='index'),
url(r'^details/(?P<id>\d+)/$',views.details, name ='details'),
];