Re: like query django
i have 1.8 version Τη Τρίτη, 19 Ιανουαρίου 2016 - 5:35:09 μ.μ. UTC+2, ο χρήστης Xristos Xristoou έγραψε: > > hello, > > > i want to create a query for likes in my post details > > my html tags > > {{movies.likes}} peaple liked this article > Like > > > my urls > > > url(r'^view/(?P[^\.]+)/$', views.view_post, name='view_post'), > > url(r'^(?P[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 work > > > Page 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: > >1. ^admin/ >2. ^$ [name='index'] >3. ^view/(?P[^\.]+)/$[name='view_post'] >4. ^category/(?P[\w-]+)/$[name='view_category'] > >5. ^(?P[0−9]+)/$ [name='like_post'] >6. ^media\/(?P.*)$ > > The current URL, like/1/, didn't match any of these. > > > > any idea ? > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/45b26eff-7d76-4961-b605-ab7d8481b2da%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: like query django
On Jan 22, 2016 1:08 AM, "Xristos Xristoou" 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 -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CA%2Be%2BciWDUu79tnxZGk_jV6V78ZK8FBBPa%3DZjv4XNZgL_%2Bo91dw%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
Re: like query django
look my version django cant not be use url 'like_post' because show me errow only 1.5 version django can use that Τη Τρίτη, 19 Ιανουαρίου 2016 - 5:35:09 μ.μ. UTC+2, ο χρήστης Xristos Xristoou έγραψε: > > hello, > > > i want to create a query for likes in my post details > > my html tags > > {{movies.likes}} peaple liked this article > Like > > > my urls > > > url(r'^view/(?P[^\.]+)/$', views.view_post, name='view_post'), > > url(r'^(?P[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 work > > > Page 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: > >1. ^admin/ >2. ^$ [name='index'] >3. ^view/(?P[^\.]+)/$[name='view_post'] >4. ^category/(?P[\w-]+)/$[name='view_category'] > >5. ^(?P[0−9]+)/$ [name='like_post'] >6. ^media\/(?P.*)$ > > The current URL, like/1/, didn't match any of these. > > > > any idea ? > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/c9b86b2e-ca01-4a52-ad8a-65849dba5d7a%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: like query django
On Tue, Jan 19, 2016 at 10:56 AM, Xristos Xristoou wrote: > 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 ? > Can you post your template with the changes you made? And the errors that you are receiving? -James -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CA%2Be%2BciUZJEdb8iEm3imYz1AxrO2qZphih04CbhF-DRLp-39Vgg%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
Re: like query django
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 ? Τη Τρίτη, 19 Ιανουαρίου 2016 - 5:35:09 μ.μ. UTC+2, ο χρήστης Xristos Xristoou έγραψε: > > hello, > > > i want to create a query for likes in my post details > > my html tags > > {{movies.likes}} peaple liked this article > Like > > > my urls > > > url(r'^view/(?P[^\.]+)/$', views.view_post, name='view_post'), > > url(r'^(?P[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 work > > > Page not found (404)Request Method:GETRequest > URL:http://127.0.0.1:8000/like/1/ > > Using the URLconf defined in categories1.urls, Django tried these URL > patterns, in this order: > >1. ^admin/ >2. ^$ [name='index'] >3. ^view/(?P[^\.]+)/$[name='view_post'] >4. ^category/(?P[\w-]+)/$[name='view_category'] > >5. ^(?P[0−9]+)/$ [name='like_post'] >6. ^media\/(?P.*)$ > > The current URL, like/1/, didn't match any of these. > > > > any idea ? > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/24bb10c8-98a2-445d-8de2-5abf0f5a618e%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: like query django
> > {{movies.likes}} peaple liked this article > Like > > > This is not how you should generate URL's within your templates. You should be using the {% url %} tag to automatically generate them: Like If using the slug in your urls.conf, your {% url %} tag would look something like this: Like See https://docs.djangoproject.com/en/dev/intro/tutorial03/#removing-hardcoded-urls-in-templates my urls > > > url(r'^view/(?P[^\.]+)/$', views.view_post, name='view_post'), > > url(r'^(?P[0−9]+)/$', views.like_post, name='like_post'), > > Your urls.conf should also be modified to avoid clashes down the road. I would recommend changing this line to imply that you are viewing the post, rather than prefixing the verb 'view' on the URL with no reference as to what type of object you are viewing: url(r'^post/(?P[^\.]+)/$', views.view_post, name='view_post'), As of now, you are using mysite.com/5 to indicate that you want to like a post, which makes it difficult to discern that is what you are doing. Something like this would work. url(r'^post/(?P[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[^\.]+)/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. See https://docs.djangoproject.com/en/dev/intro/tutorial03/#writing-more-views You'll notice they have the verb (action word) after the identifier for the item that is being acted upon. In psuedo-code English, this translates to 'here is the post that I want to like' rather than 'I am liking something, here is a post'. Not sure if that translates well to other languages if English isn't your first language. You'll want to set things up this way because it will help keep your URL's together in one configuration file, and will make your URL scheme much simpler. Much easier to keep track of all the actions that you can perform for a particular post (create, update, delete, comment, like, etc.) rather than having an extensively long list of actions that have actionable objects. If you add more content types, like a 'news article', then you'll have to modify two sets of urls.py files or stanzas, one for viewing the article, and another for the extra actions that can be taken on that article, which gets cumbersome and difficult to manage. > > 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) > > > You should be using reverse() here rather than the actual URL. There are examples of this in the tutorial for Django: https://docs.djangoproject.com/en/1.9/intro/tutorial01/ > but i have error not work > > > Page 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: > >1. ^admin/ >2. ^$ [name='index'] >3. ^view/(?P[^\.]+)/$[name='view_post'] >4. ^category/(?P[\w-]+)/$[name='view_category'] >5. ^(?P[0−9]+)/$ [name='like_post'] >6. ^media\/(?P.*)$ > > The current URL, like/1/, didn't match any of these. > > > > any idea ? > > You are trying to reach /like/1/, but your urls.py file is configured only to look for /1/ (line 5). Please run through the tutorial, which will show you step by step how these processes work together, and should give you a good basis for URL design. https://docs.djangoproject.com/en/1.9/intro/tutorial01/ -James -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CA%2Be%2BciVWAmZwiTTk36txn1pe8MsXMqnne3W0OvCiV5puBLTvdA%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
Re: like query django
not work again florian same error again Τη Τρίτη, 19 Ιανουαρίου 2016 - 5:35:09 μ.μ. UTC+2, ο χρήστης Xristos Xristoou έγραψε: > > hello, > > > i want to create a query for likes in my post details > > my html tags > > {{movies.likes}} peaple liked this article > Like > > > my urls > > > url(r'^view/(?P[^\.]+)/$', views.view_post, name='view_post'), > > url(r'^(?P[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 work > > > Page not found (404)Request Method:GETRequest > URL:http://127.0.0.1:8000/like/1/ > > Using the URLconf defined in categories1.urls, Django tried these URL > patterns, in this order: > >1. ^admin/ >2. ^$ [name='index'] >3. ^view/(?P[^\.]+)/$[name='view_post'] >4. ^category/(?P[\w-]+)/$[name='view_category'] > >5. ^(?P[0−9]+)/$ [name='like_post'] >6. ^media\/(?P.*)$ > > The current URL, like/1/, didn't match any of these. > > > > any idea ? > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/d649cb3c-63cc-4793-ac08-5ac8af7951ac%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: like query django
On 19/01/16 16:35, Xristos Xristoou wrote: > url(r'^view/(?P[^\.]+)/$', views.view_post, name='view_post'), > url(r'^(?P[0−9]+)/$', views.like_post, name='like_post'), this defines urls like /1/ > The current URL, |like/1/|, didn't match any of these. of course it doesn't, you didn't define a like/... url pattern -- Florian -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/569E5F25.50500%40ist-total.org. For more options, visit https://groups.google.com/d/optout.
like query django
hello, i want to create a query for likes in my post details my html tags {{movies.likes}} peaple liked this article Like my urls url(r'^view/(?P[^\.]+)/$', views.view_post, name='view_post'), url(r'^(?P[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 work Page not found (404)Request Method:GETRequest URL:http://127.0.0.1:8000/like/1/ Using the URLconf defined in categories1.urls, Django tried these URL patterns, in this order: 1. ^admin/ 2. ^$ [name='index'] 3. ^view/(?P[^\.]+)/$[name='view_post'] 4. ^category/(?P[\w-]+)/$[name='view_category'] 5. ^(?P[0−9]+)/$ [name='like_post'] 6. ^media\/(?P.*)$ The current URL, like/1/, didn't match any of these. any idea ? -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/bd58b974-1c93-498b-a9b3-30503e209e51%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.