Add the photo id to the url - so instead of having the form like this:
<form action="{% url 'nowandthen:add_comment'%}" method="POST">

you add it like this:
 <form action="{% url 'nowandthen:add_comment' photo_id %}" method="POST">

and make sure that the photo_id variable is in the current context and that
the comment view accepts an id.

Regards,

Andréas


Den tis 31 mars 2020 kl 16:58 skrev Jeff Waters <water...@gmail.com>:

> I am creating a website where users can comment on photos in a gallery.
> The challenge I currently have is that Django is not able to determine
> which of the photos the comment 'submit' button relates to.
>
> This is my HTML code for the photo gallery:
>
>         <h2>comments</h2>
>                 {% if not comments %}
>                 No comments
>                 {% endif %}
>                 {% for x in comment %}
>                 <div class="comments" style="padding: 10px;">
>                     <p class="font-weight-bold">
>                         <h4>Comment by</h4> {{ x.user }}
>                         <span class=" text-muted font-weight-normal">
>                             {{ x.created_on }}
>                         </span>
>                     </p>
>                     {{ x.body | linebreaks }}
>                 </div>
>                 {% endfor %}
>             </div>
>             <div class="card-body">
>                 {% if new_comment %}
>                 <h2>Your comment has been posted.</h2>
>                 {% else %}
>                 <h3>Leave a comment</h3>
>                 <form action="{% url 'nowandthen:add_comment'%}"
> method="POST">
>                     {{ comment_form.as_p }}
>                     {% csrf_token %}
>                     <button type="submit" class="btn btn-primary
> btn-lg">Submit</button>
>                 {% endif %}
>
> How do you suggest I overcome this problem, please?
>
> Thanks
>
> Jeff
>
> --
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/cabe2b94-bf00-4394-b699-8a15d48247d2%40googlegroups.com
> .
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAK4qSCcYWsEjhdP%3DxLOMUeUPmeH6RssocH48L7v%3DMhHJf11-3g%40mail.gmail.com.

Reply via email to