<p>{{movies.likes}} peaple liked this article</p>
<p><a href="/like/{{post.id}}">Like</a></p>
my urls
url(r'^view/(?P<slug>[^\.]+)/$', views.view_post, name='view_post'),
url(r'^(?P<pk>[0−9]+)/$', views.like_post, name='like_post'),
my view
def like_post(request,pk=1):
a=Movies.objects.get(pk=pk)
count=a.likes
count+=1
a.likes=count
a.save()
return HttpResponseRedirect ( '/posts/view/%s' % pk)but i have error not workPage not found (404)
Request Method: GET Request URL: http://127.0.0.1:8000/like/1/ Using the URLconf defined in
categories1.urls, Django tried these URL patterns, in this order:
- ^admin/
- ^$ [name='index']
- ^view/(?P<slug>[^\.]+)/$[name='view_post']
- ^category/(?P<slug>[\w-]+)/$[name='view_category']
- ^(?P<pk>[0−9]+)/$ [name='like_post']
- ^media\/(?P<path>.*)$
The current URL,
like/1/, didn't match any of these.any idea ?
<p>{{movies.likes}} peaple liked this article</p>
<p><a href="/like/{{post.id}}">Like</a></p>
<p><a href="{% url 'like_post' post.id %}">Like</a></p>
<p><a href="{% url 'like_post' post.slug %}">Like</a></p>
my urlsurl(r'^view/(?P<slug>[^\.]+)/$', views.view_post, name='view_post'),url(r'^(?P<pk>[0−9]+)/$', views.like_post, name='like_post'),
url(r'^post/(?P<slug>[^\.]+)/$', views.view_post, name='view_post'),
url(r'^post/(?P<pk>[0−9]+)/like/$', views.like_post, name='like_post'),You can also do this using the slug if you want to keep your URL's looking the same:
url(r'^post/(?P<slug>[^\.]+)/like/$', views.like_post, name='like_post'),
I would recommend always using the slug, or always using the PK, but not intermixing the two if you can avoid it (keeps things easier to remember when doing more advanced operations). If you care about SEO, you'll probably want to use the slug.
my viewdef like_post(request,pk=1):
a=Movies.objects.get(pk=pk)
count=a.likes
count+=1
a.likes=count
a.save()
return HttpResponseRedirect ( '/posts/view/%s' % pk)
but i have error not workPage not found (404)
Request Method: GET Request URL: http://127.0.0.1:8000/like/1/ Using the URLconf defined in
categories1.urls, Django tried these URL patterns, in this order:
- ^admin/
- ^$ [name='index']
- ^view/(?P<slug>[^\.]+)/$[name='view_post']
- ^category/(?P<slug>[\w-]+)/$[name='view_category']
- ^(?P<pk>[0−9]+)/$ [name='like_post']
- ^media\/(?P<path>.*)$
The current URL,
like/1/, didn't match any of these.any idea ?
i follow you not work again first i cant use {% url %} show me template error,i thing so i am is very noob
must necesery tu urls for that ?
On Jan 22, 2016 1:08 AM, "Xristos Xristoou" <sax...@gmail.com> wrote:
>
> look my version django cant not be use url 'like_post' because show me errow only 1.5 version django can use that
>
I have no idea what you are trying to say here, sorry.
Are you using Django 1.5? If so, you should upgrade immediately.
Without any further information posted, I'm afraid I can't be of much help.
-James