我正在使用django 1.7 & python 3.4 我試圖執行跟進和取消關注用戶到我的網站,但我卡住了。 urls.pyNoReverseMatch found
url(r'^user/', include('myuserprofile.urls'),),
myuserprofile.urls.py
urlpatterns = patterns('',
url(r'^(?P<slug>[^/]+)/$', 'myuserprofile.views.profile', name='profile'),
url(r'^(?P<slug>[^/]+)/follow/$', 'myuserprofile.views.follow', name='follow'),
url(r'^(?P<slug>[^/]+)/unfollow/$', 'myuserprofile.views.unfollow', name='unfollow'),
views.py
@login_required
def follow(request):
myuser = request.user.id
if request.method == 'POST':
to_user = MyUser.objects.get(id=request.POST['to_user'])
rel, created = Relationship.objects.get_or_create(
from_user=myuser.myuserprofile,
to_user=to_user,
defaults={'status': 'following'}
)
else:
return HttpResponseRedirect(reverse('/'))
if not created:
rel.status = 'following'
rel.save()
與模板部分是這樣的:
<form action="{% if relationship.status == 'F' %}{% url 'unfollow' %}{% else %}{% url 'follow' %}{% endif %}" method="POST">
爲反向'跟隨'與ar未找到guments'()'和關鍵字參數'{}'。 1個模式嘗試:['user /(?P [^ /] +)/ follow/$']
我試過了也。即使這是顯示相同的錯誤 – sprksh 2015-03-13 11:32:21
該URL模式需要一個參數'slug'來計算它可以在模板中使用'{%url'myuserprofile:unfollow'%}' –
bvidal
2015-03-13 12:10:50