I am currently trying to create a like button for my posts in Django
I have reached to the part where I can add a like but I am facing difficulty writing the code related to the view which linking the PostListView if there is user who liked it or not. I am getting an error: page Error 404 although everything is correct
this the views:
This is the model
class Post(models.Model):
designer = models.ForeignKey(User, on_delete=models.CASCADE)
title = models.CharField(max_length=100)
date_posted = models.DateTimeField(default=timezone.now)
likes = models.ManyToManyField(User, blank=True, related_name='likes')
def __str__(self):
return self.title
Here is the
path('like/', like_post, name='like_post'),
here is the template:
{% extends "base.html"%} {% block content %} {% for post in posts %}
<div style="padding-top: 200 px;"><strong>{{post.title}}</strong></div>
<form action="{% url 'score:like_post'%}" method="POST" class="ui form">
{% csrf_token %} {% if is_like %}
<input type="hidden" name="post_id" value="{{post.id}}" />
<button class="ui button positive" type="submit">Unlike</button>
{% else %}
<button class="ui button negative" type="submit">Like</button>
{% endif %}
</form>
<strong>Likes </strong>
{% endfor %} {% endblock content %}
--
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...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/583492d8-5252-4f86-8e8f-7593b582d404%40googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to django...@googlegroups.com.
% extends "base.html"%} {% block content %} {% for post in posts %}
<div style="padding-top: 200 px;"><strong>{{post.title}}</strong></div>
<form action="{% url 'score:like_post'%}" method="POST" class="ui form">
<input type="hidden" name="post_id" value="{{post.id}}" />
{% csrf_token %} {% if is_like %} <button class="ui button positive" type="submit">Unlike</button>
{% else %}
<button class="ui button negative" type="submit">Like</button>
{% endif %}
</form>
{% endfor %} {% endblock content %}
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/aee352a1-2938-42a6-98cb-5d602abba567%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/aee352a1-2938-42a6-98cb-5d602abba567%40googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/58be585f-357c-4454-acad-6799abe2e43d%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/58be585f-357c-4454-acad-6799abe2e43d%40googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/d65b8dcb-b7e3-472d-8892-fb4c8e477109%40googlegroups.com.