Passing values from templates to views can be done by passing those values through urls.
For example ,if one has liked the book ,the id of the book has to be sent to the views (to increment the number of likes) by passing id in urls.
In templates ,say 3.html
{% if books_list %}
-
{% for b in books_list %}
{{b.name}}
Do you like this book??
url(r'^like/(?PThe above url redirects to like function(def) of views. In view.py,\d+)/$','books.views.like'),
def like(request,id): n = Books.objects.get(id=id) n.likes = n.likes+1 n.save()The ‘likes’ of the book has to be incremented by one,by getting the book by its id (which was passed through url).
No comments:
Post a Comment