Monday, March 30, 2020

Re: HTML code not being read

Your view context uses 'comment'(singular), while your template uses
'comments'(plural).  I'd chnage your view context to match the template.

On 3/30/20 9:51 AM, Jeff Waters wrote:
> Hi
>
> Thanks for getting back to me.
>
> This is from my views.py:
>
> @login_required
> def add_comment(request, image_id):
> new_comment = None
> template_name = 'add_comment.html'
> image = get_object_or_404(Picture, id=image_id)
> comment = image.comment.filter(active=True)
> new_comment = None
> # Comment posted
> if request.method == 'POST':
> comment_form = CommentForm(data=request.POST)
> if comment_form.is_valid():
> # Create Comment object and don't save to database yet
> new_comment = comment_form.save(commit=False)
> # Assign the current post to the comment
> new_comment.post = post
> # Save the comment to the database
> new_comment.save()
> else:
> comment_form = CommentForm()
>
> context = {'comment_form': comment_form, 'image': image,'comment': comment, 'new_comment': new_comment,'comment_form': comment_form}
>
> return render(request, template_name, context)
>
> Does that look correct to you?
>
> 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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/c105b434-0ffa-8861-17d3-f7824a861f4d%40fattuba.com.

No comments:

Post a Comment