Monday, March 30, 2020

Re: HTML code not being read

Here is the change I suggest:

https://gist.github.com/tubaman/bf49949f8a9369ad3db1f56d5ce7dbc0/revisions

On 3/30/20 1:03 PM, Jeff Waters wrote:
@login_required
def add_comment(requestimage_id):
    new_comment = None
    template_name = 'add_comment.html'
    image = get_object_or_404(Picture, id=image_id)
    comment = image.comments.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 = {'image': image,'comment': comment, 'new_comment': new_comment,'comment_form': comment_form}
    return render(request, template_name, context)

No comments:

Post a Comment