Re: Form not displaying

2020-03-30 Thread Jeff Waters
Will do, thanks

-- 
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/0969e788-8cea-40a0-acc8-655bfa8ab2ce%40googlegroups.com.


Re: Form not displaying

2020-03-30 Thread Ernest Thuku
There in your template...that closing form tag...is it a typing error?I
can't see the second closing tag
On Mar 30, 2020 13:23, "Ernest Thuku"  wrote:

> Try this
> On Mar 30, 2020 12:58, "Jeff Waters"  wrote:
>
>> Thanks Ernest.
>>
>> I'm not sure I follow (forgive me, I am very new to Django).
>>
>> Given that template_name is defined earlier in the method as
>> 'add_comment.html', surely what I've written is equivalent to:
>>
>> return render(request, add_comment.html, {'image': image,
>>'comments': comments,
>>'new_comment': new_comment,
>>'comment_form': comment_form})
>>
>> What should the code be instead?
>>
>> 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/ms
>> gid/django-users/8e5fcc67-5a91-4371-a51a-9860a6cc78e3%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/CAPsfuodXhoe2DXi4t3fmmSoBV1kGzS%2BpxKU5cPhC8Ux%2BHF%3D%2BFw%40mail.gmail.com.


Re: Form not displaying

2020-03-30 Thread Jeff Waters
Thanks Ernest.

I'm not sure I follow (forgive me, I am very new to Django).

Given that template_name is defined earlier in the method as 
'add_comment.html', surely what I've written is equivalent to:

return render(request, add_comment.html, {'image': image,
   'comments': comments,
   'new_comment': new_comment,
   'comment_form': comment_form})

What should the code be instead?

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/8e5fcc67-5a91-4371-a51a-9860a6cc78e3%40googlegroups.com.


Re: Form not displaying

2020-03-30 Thread Ernest Thuku
In the views why have you used templane_name while you not using class
based views...try and change that to render the template using request
On Mar 30, 2020 11:55, "Jeff Waters"  wrote:

> Sure. It's as follows:
>
> @login_required
> def add_comment(request, image_id):
> template_name = 'add_comment.html'
> image = get_object_or_404(Picture, id=image_id)
> comments = 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()
>
> return render(request, template_name, {'image': image,
>'comments': comments,
>'new_comment': new_comment,
>'comment_form': comment_form})
>
>
>
> 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/8e0f5a28-7a48-4037-aba5-ea591a81d397%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/CAPsfuofgALu7-qZFeVyxxr4LJLtAwnsFhnYvsOSD6QMBmH17bw%40mail.gmail.com.


Re: Form not displaying

2020-03-30 Thread Jeff Waters
Sure. It's as follows:

@login_required
def add_comment(request, image_id):
template_name = 'add_comment.html'
image = get_object_or_404(Picture, id=image_id)
comments = 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()

return render(request, template_name, {'image': image,
   'comments': comments,
   'new_comment': new_comment,
   'comment_form': comment_form})



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/8e0f5a28-7a48-4037-aba5-ea591a81d397%40googlegroups.com.


Re: Form not displaying

2020-03-29 Thread Ernest Thuku
Can you display your views please?
On Mar 30, 2020 05:13, "Jeff Waters"  wrote:

> Apologies if I'm posting this twice - my original message isn't displayed
> in the list of messages.
>
> I am creating a website using Django. I'd like to give users the chance to
> comment on pictures they have posted. I have created a comment model and a
> comment form, and put the following code into the HTML document for the
> photo gallery:
>
> Leave a comment
> 
> {{ comment_form.as_p }}
> {% csrf_token %}
> Submit
>  However, the form is not displaying - there is nothing between 'Leave a
> comment' and the submit button on the page. I don't understand this as my
> form in forms.py appears to be configured correctly:
>
> class CommentForm(forms.ModelForm):
> body = forms.CharField(help_text="What is your comment?",
> widget=forms.TextInput(attrs={'size': '1000'}),
>required=True)
>
> class Meta:
> model = Comment
> fields = ('body',)
> def as_p(self):
> # Returns this form rendered as HTML s.
> return self._html_output(
> normal_row='%(field)s',
> error_row='%s',
> row_ender='',
> help_text_html=' %s',
> errors_on_separate_row=True)`
> So does my model in models.py:
>
> class Comment(models.Model):
> COMMENT_MAX_LENGTH = 1000
> image = models.ForeignKey(Picture, on_delete=models.CASCADE,
> related_name="comments")
> user = models.ForeignKey(UserProfile, on_delete=models.CASCADE)
> body = models.TextField(max_length=COMMENT_MAX_LENGTH)
> created_on = models.DateTimeField(auto_now_add=True)
> active = models.BooleanField(default=False)
>
> class Meta:
> ordering = ['created_on']
>
> def __str__(self):
> return 'Comment {} by {}'.format(self.body, self.user)
>
> When I go into the source code on the site, it shows that the form is
> hidden. Also, when I change comment_form.as_p to something random, no error
> messages are generated. It's like something is causing Django to skip past
> that bit of code.
>
> I'd really appreciate any suggestions anyone could please offer.
>
> 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/ac7ac525-9bc4-4043-a142-b97b1d3d0e5c%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/CAPsfuofTW8RywcqoK6T4SZz%2BqtkAWHHg7UAoshXOupOh6nj_WQ%40mail.gmail.com.


Form not displaying

2020-03-29 Thread Jeff Waters
Apologies if I'm posting this twice - my original message isn't displayed in 
the list of messages.

I am creating a website using Django. I'd like to give users the chance to 
comment on pictures they have posted. I have created a comment model and a 
comment form, and put the following code into the HTML document for the photo 
gallery:

Leave a comment

{{ comment_form.as_p }}
{% csrf_token %}
Submit
s.
return self._html_output(
normal_row='%(field)s',
error_row='%s',
row_ender='',
help_text_html=' %s',
errors_on_separate_row=True)`
So does my model in models.py:

class Comment(models.Model):
COMMENT_MAX_LENGTH = 1000
image = models.ForeignKey(Picture, on_delete=models.CASCADE, 
related_name="comments")
user = models.ForeignKey(UserProfile, on_delete=models.CASCADE)
body = models.TextField(max_length=COMMENT_MAX_LENGTH)
created_on = models.DateTimeField(auto_now_add=True)
active = models.BooleanField(default=False)

class Meta:
ordering = ['created_on']

def __str__(self):
return 'Comment {} by {}'.format(self.body, self.user)

When I go into the source code on the site, it shows that the form is hidden. 
Also, when I change comment_form.as_p to something random, no error messages 
are generated. It's like something is causing Django to skip past that bit of 
code.

I'd really appreciate any suggestions anyone could please offer.

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/ac7ac525-9bc4-4043-a142-b97b1d3d0e5c%40googlegroups.com.


Re: Django Comments Form not Displaying

2012-02-12 Thread coded kid
Thanks guys. @matias I tried your solution, and the post button
appeared. After clicking on it, I get 'COMMENT POST NOT ALLOWED (404)'
Please whats wrong?



On Feb 12, 4:37 pm, Matías Aguirre  wrote:
> Excerpts from Michael P. Soulier's message of 2012-02-12 14:16:26 -0200:
>
>
>
>
>
> > On 12/02/12 coded kid said:
>
> > > Below is the codes in my comments/form.html
> > > {% load comments i18n %}
> > > {% csrf_token
> > > %}
> > >   {% if next %} > > value="{{ next }}" />{% endif %}
> > >   {% for field in form %}
> > >     {% if field.is_hidden %}
> > >       {{ field }}
> > >     {% else %}
> > >       {% if field.errors %}{{ field.errors }}{% endif %}
> > >        > >         {% if field.errors %} class="error"{% endif %}
> > >         {% ifequal field.name "honeypot" %} style="display:none;"{%
> > > endifequal %}>
> > >         {{ field.label_tag }} {{ field }}
> > >       
> > >     {% endif %}
> > >   {% endfor %}
> > >   
> > >     
> > >      > > value="{% trans "Preview" %}" />
> > >   
> > > 
>
> > You have conditionals on all output. If you're seeing a blank page, perhaps
> > those conditionals are all false. Put in some unconditional content and see 
> > if
> > it renders, and then start testing your conditionals.
>
> "/comments/post" is decorated by require_POST, that means that POST is the 
> only
> method allowed to access that view, check your response, you should be getting
> a 405 response.
>
> You should include the form in the page you want it to display, let's say
> a blog post page, but if you want the form on a single page, then you need to
> define a different URL and view to render the template.
>
> Regards,
> Matías
> --
> Matías Aguirre (matiasagui...@gmail.com)

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Django Comments Form not Displaying

2012-02-12 Thread Matías Aguirre
Excerpts from Michael P. Soulier's message of 2012-02-12 14:16:26 -0200:
> On 12/02/12 coded kid said:
> 
> > Below is the codes in my comments/form.html
> > {% load comments i18n %}
> > {% csrf_token
> > %}
> >   {% if next %} > value="{{ next }}" />{% endif %}
> >   {% for field in form %}
> > {% if field.is_hidden %}
> >   {{ field }}
> > {% else %}
> >   {% if field.errors %}{{ field.errors }}{% endif %}
> >> {% if field.errors %} class="error"{% endif %}
> > {% ifequal field.name "honeypot" %} style="display:none;"{%
> > endifequal %}>
> > {{ field.label_tag }} {{ field }}
> >   
> > {% endif %}
> >   {% endfor %}
> >   
> > 
> >  > value="{% trans "Preview" %}" />
> >   
> > 
> 
> You have conditionals on all output. If you're seeing a blank page, perhaps
> those conditionals are all false. Put in some unconditional content and see if
> it renders, and then start testing your conditionals.

"/comments/post" is decorated by require_POST, that means that POST is the only
method allowed to access that view, check your response, you should be getting
a 405 response.

You should include the form in the page you want it to display, let's say
a blog post page, but if you want the form on a single page, then you need to
define a different URL and view to render the template.

Regards,
Matías
-- 
Matías Aguirre (matiasagui...@gmail.com)

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Django Comments Form not Displaying

2012-02-12 Thread Michael P. Soulier
On 12/02/12 coded kid said:

> Below is the codes in my comments/form.html
> {% load comments i18n %}
> {% csrf_token
> %}
>   {% if next %} value="{{ next }}" />{% endif %}
>   {% for field in form %}
> {% if field.is_hidden %}
>   {{ field }}
> {% else %}
>   {% if field.errors %}{{ field.errors }}{% endif %}
>{% if field.errors %} class="error"{% endif %}
> {% ifequal field.name "honeypot" %} style="display:none;"{%
> endifequal %}>
> {{ field.label_tag }} {{ field }}
>   
> {% endif %}
>   {% endfor %}
>   
> 
>  value="{% trans "Preview" %}" />
>   
> 

You have conditionals on all output. If you're seeing a blank page, perhaps
those conditionals are all false. Put in some unconditional content and see if
it renders, and then start testing your conditionals.

Mike

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Django Comments Form not Displaying

2012-02-12 Thread coded kid
Hi guys, please help me out with django-comments form. I added :
'django.contrib.comments',  to INSTALLED APPS

(r'^comments/', include('django.contrib.comments.urls')), to urls.py
and I copied the default templates from
django.contrib.comments.templates.comments to my app templates
directory.

 After doing that, I visit localhost:8000/comments/posts and the page
is not showing me any comments form, it just showing me a white blank
page. What I'm I doing wrong?

Below is the codes in my comments/form.html
{% load comments i18n %}
{% csrf_token
%}
  {% if next %}{% endif %}
  {% for field in form %}
{% if field.is_hidden %}
  {{ field }}
{% else %}
  {% if field.errors %}{{ field.errors }}{% endif %}
  
{{ field.label_tag }} {{ field }}
  
{% endif %}
  {% endfor %}
  


  

Hope to hear from you soon.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.