Re: HTML code not being read
Did you connect your template folder on settings.py ? Sent from my iPhone > On Mar 30, 2020, at 11:06 PM, Aly_34_04 MR_34_04 > wrote: > > show me your views > >> On Monday, March 30, 2020 at 5:13:49 PM UTC+3, Jeff Waters wrote: >> Hi >> I have written some code that allows users of a website to comment on photos >> in a picture gallery, using a form. However, when I test the code, no >> comments are displayed. >> >> It would appear that Django is not processing the following code (from my >> HTML file for the photo gallery), given that 'Comment by' is not displayed >> on screen: >> >> {% for comment in comments %} >> >> >> Comment by {{ comment.user }} >> >> {{ comment.created_on }} >> >> >> {{ comment.body | linebreaks }} >> >> {% endfor %} >> >> Does anyone have any suggestions as to how I can fix this, please? >> >> Thank 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+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/django-users/85705553-9cd4-49e2-878e-8c0a903bc79f%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/8D103D55-152B-4AE6-836C-D7B1D272B06E%40gmail.com.
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(request, image_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) -- 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/bacdf5da-e1cb-09c4-568d-a0bc70362e1a%40fattuba.com.
Re: HTML code not being read
Let's see your url.py On Mon, Mar 30, 2020, 10:03 PM Jeff Waters wrote: > I've modified my code a bit to try (unsuccessfully!) to get this working. > > My views.py is now as follows: > > @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.comments.filter(active=True) > new_comment = None > # Comment posted > if request.method == 'POST': > comment_form = CommentForm(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) > > My html code for the gallery is now: > > comments > {% if not comments %} > No comments > {% endif %} > {% for comment in comment %} > > > Comment by {{ comment.user }} > > {{ comment.created_on }} > > > {{ comment.body | linebreaks }} > > {% endfor %} > > The problem I now have is that I now get the following error message: > Reverse for 'add_comment' with arguments '('',)' not found. 1 pattern(s) > tried: ['add_comment/(?P[0-9]+)$'] > > Any suggestions would be much appreciated. > > 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/e2212e12-d379-4bcb-8c96-eff4c89c5245%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/CAHyB84rnc11SOpJJvwtyzoWkf%3D77jBjzKNctBeN3S%3D9ipKRa%3Dg%40mail.gmail.com.
Re: HTML code not being read
I've modified my code a bit to try (unsuccessfully!) to get this working. My views.py is now as follows: @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.comments.filter(active=True) new_comment = None # Comment posted if request.method == 'POST': comment_form = CommentForm(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) My html code for the gallery is now: comments {% if not comments %} No comments {% endif %} {% for comment in comment %} Comment by {{ comment.user }} {{ comment.created_on }} {{ comment.body | linebreaks }} {% endfor %} The problem I now have is that I now get the following error message: Reverse for 'add_comment' with arguments '('',)' not found. 1 pattern(s) tried: ['add_comment/(?P[0-9]+)$'] Any suggestions would be much appreciated. 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/e2212e12-d379-4bcb-8c96-eff4c89c5245%40googlegroups.com.
Re: HTML code not being read
show me your views On Monday, March 30, 2020 at 5:13:49 PM UTC+3, Jeff Waters wrote: > > Hi > > I have written some code that allows users of a website to comment on > photos in a picture gallery, using a form. However, when I test the code, > no comments are displayed. > > It would appear that Django is not processing the following code (from my > HTML file for the photo gallery), given that 'Comment by' is not displayed > on screen: > > {% for comment in comments %} > > > Comment by {{ comment.user }} > > {{ comment.created_on }} > > > {{ comment.body | linebreaks }} > > {% endfor %} > > Does anyone have any suggestions as to how I can fix this, please? > > Thank 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+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/85705553-9cd4-49e2-878e-8c0a903bc79f%40googlegroups.com.
Re: HTML code not being read
Thanks guys I previously had 'comments' in the plural in views.py, but had the same problem. Am I right in thinking that Django recognises that 'comments' is the plural of 'comment', so if it knows from the view what a comment is, it knows what comments are? 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/055a99d8-a18f-4235-b133-feb9dd206930%40googlegroups.com.
Re: HTML code not being read
What you passed to the context in your views.py is 'comment', but you are looping through 'comments' in the template On Mon, Mar 30, 2020, 3:52 PM 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+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/django-users/7f92c0a3-07cc-4b33-ba37-e32bc24c5386%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/CAHyB84o4GGgDBEPSo0wNFd1F%3DK9dXk3MzVjRFm%2BrmBtYOq%2BBZQ%40mail.gmail.com.
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+unsubscr...@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.
Re: HTML code not being read
Hi I'm not sure what you mean by 'Have you all ready use a content that define your content'. I'm new to Django, so am not familiar with all of the terminology yet. Can you elaborate 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/5e97ab38-2663-4943-b4b8-bf6e3ea744a5%40googlegroups.com.
Re: HTML code not being read
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+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/7f92c0a3-07cc-4b33-ba37-e32bc24c5386%40googlegroups.com.
Re: HTML code not being read
Have you all ready use a content that define your content On Mon, 30 Mar 2020, 17:14 Jeff Waters, wrote: > Hi > > I have written some code that allows users of a website to comment on > photos in a picture gallery, using a form. However, when I test the code, > no comments are displayed. > > It would appear that Django is not processing the following code (from my > HTML file for the photo gallery), given that 'Comment by' is not displayed > on screen: > > {% for comment in comments %} > > > Comment by {{ comment.user }} > > {{ comment.created_on }} > > > {{ comment.body | linebreaks }} > > {% endfor %} > > Does anyone have any suggestions as to how I can fix this, please? > > Thank 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+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/django-users/4666d2ec-e4d8-492d-8203-03dfecd29d6a%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/CAKNQJk5Mys3t7WLeBatbZ7Mg8Bj4WaMabELqmWGKiUvHBguQ_Q%40mail.gmail.com.
Re: HTML code not being read
The problem might not be from the HTML template but the View. All the HTML elements within your for loop will not display if there are no records to loop through in "comments" On Mon, Mar 30, 2020, 3:14 PM Jeff Waters wrote: > Hi > > I have written some code that allows users of a website to comment on > photos in a picture gallery, using a form. However, when I test the code, > no comments are displayed. > > It would appear that Django is not processing the following code (from my > HTML file for the photo gallery), given that 'Comment by' is not displayed > on screen: > > {% for comment in comments %} > > > Comment by {{ comment.user }} > > {{ comment.created_on }} > > > {{ comment.body | linebreaks }} > > {% endfor %} > > Does anyone have any suggestions as to how I can fix this, please? > > Thank 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+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/django-users/4666d2ec-e4d8-492d-8203-03dfecd29d6a%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/CAHyB84rnKyBKR8rZbV2zij5QfK0FyA9F6DWCRo2v01QD48T%3DDQ%40mail.gmail.com.