-1
這裏是我的urls.py:NoReverseMatch在/股票/ 5/
urlpatterns=[
url(r'^login/$', views.loginview, name='login'),
url(r'logout/$', views.logoutview, name='logout'),
url(r'signup/$', views.signup, name='signup'),
url(r'^stocks/(?P<pk>[0-9])/$', views.successful_login, name='successful_login'),
url(r'^buystocks/(?P<pk>[0-9])/(?P<sn>[A-Z])/buy/$', views.buy, name='buy')
]
這是我從模板片段:
<form method="post" action="{% url 'buy' pk=user.id sn=stock.stock_name %}" >
這是我收到的錯誤:
NoReverseMatch at /stocks/5/
Reverse for 'buy' with keyword arguments '{u'pk': 5, u'sn': u'HDFC'}' not found. 1 pattern(s) tried: ['buystocks/(?P<pk>[0-9])/(?P<sn>[A-Z])/buy/$']
您的'pk's是否在0-9範圍內?你目前的正則表達式不支持數字9,你應該在'[0-9]'後面加一個'+' –
是的,他們現在在0-9範圍內,但是我仍然會添加一個'+'。謝謝爲了指出這一點。 –