How to use next with comments?

11 views
Skip to first unread message

Kevin Fullerton

unread,
May 27, 2009, 4:02:06 PM5/27/09
to django...@googlegroups.com
I'm working with django.contrib.comments at the moment, and so far most
things are working as expected.

I'm building the submission form using {% get_comment_form for object as
form %} and have added the following as part of the form

<input type="hidden" name="next" value="{{ object.get_absolute_url }}" />

As I understand it, that should force comments to redirect to that URL
after successful submission - the problem is it doesn't.

If I view the source of the submission form, the tag is there and
populated correctly - if I preview or submit an incorrect POST then it
brings up the preview screen, but there isn't a hidden next field in
there.

If I submit a correctly formed comment, it brings up the "Thank you for
your comment" template but doesn't redirect back to the original object.

I've tried removing the hidden field and doing

<form action="{% comment_form_target %}?next={{ object.get_absolute_url
}}" method="POST">

and have the same problem - is this a known problem, or is it developer
error (me)?

Many thanks

Kevin

Eric Abrahamsen

unread,
May 27, 2009, 8:50:57 PM5/27/09
to django...@googlegroups.com
It's a known problem and the patch for this is already in trunk –
update to r10418 or later, or you can stick the patch in yourself
(it's a pretty clean one-liner).

HTH,
Eric


>
> Many thanks
>
> Kevin
>
>
> >

Kevin Fullerton

unread,
May 28, 2009, 3:17:39 AM5/28/09
to django...@googlegroups.com
On Thu, May 28, 2009 01:50, Eric Abrahamsen wrote:
>
> On May 28, 2009, at 4:02 AM, Kevin Fullerton wrote:
>
>>
>> I'm working with django.contrib.comments at the moment, and so far
>> most
>> things are working as expected.

<snip>

>
> It's a known problem and the patch for this is already in trunk –
> update to r10418 or later, or you can stick the patch in yourself
> (it's a pretty clean one-liner).
>
> HTH,
> Eric
>

Thanks Eric, I'm running r10858 and having this problem - I've removed any
comments templates I've overridden in my application and still getting the
same problem - when the next parameter is passed in, it gets ignored :(

Many thanks

Kevin

Eric Abrahamsen

unread,
May 28, 2009, 9:31:24 AM5/28/09
to django...@googlegroups.com
The default comment form does not include a next parameter, so if you
don't override the builtin comment templates you won't get any next
parameters in the forms. The most sure way of doing this is using a
custom comment form with a next field – that way the form will include
the field no matter where it is used in your project. Otherwise, you
can use custom comment form and preview form templates – I'm guessing
you originally didn't have a custom preview template, which meant it
was using the builtin one, which meant... no next parameter in the
html form.

Hopefully something in there will work!

Eric

>
> Many thanks
>
> Kevin
>
>
> >

Kevin Fullerton

unread,
May 28, 2009, 5:40:31 PM5/28/09
to django...@googlegroups.com

On Thu, May 28, 2009 14:31, Eric Abrahamsen wrote:
>
> The default comment form does not include a next parameter, so if you
> don't override the builtin comment templates you won't get any next
> parameters in the forms. The most sure way of doing this is using a
> custom comment form with a next field – that way the form will include
> the field no matter where it is used in your project. Otherwise, you
> can use custom comment form and preview form templates – I'm guessing
> you originally didn't have a custom preview template, which meant it
> was using the builtin one, which meant... no next parameter in the
> html form.

Looking at the django source the next parameter is included in the default
preview template -
http://code.djangoproject.com/browser/django/trunk/django/contrib/comments/templates/comments/preview.html
line 9

The code I'm using to submit the comment looks similar to

{% get_comment_form for object as form %}

<form action="{% comment_form_target
%}?next=http://blog.kenwa-solutions.co.uk/" method="POST">


<input type="hidden" name="next" value="{{ object.get_absolute_url }}" />

<snip />

So I'm not sure why the default preview form isn't picking it up

Many thanks

Kevin

Dmitry Dzhus

unread,
May 30, 2009, 8:57:45 AM5/30/09
to django...@googlegroups.com
Kevin Fullerton wrote:
> I'm working with django.contrib.comments at the moment, and so far most
> things are working as expected.
>
> I'm building the submission form using {% get_comment_form for object as
> form %} and have added the following as part of the form
>
> <input type="hidden" name="next" value="{{ object.get_absolute_url }}" />
>
> As I understand it, that should force comments to redirect to that URL
> after successful submission - the problem is it doesn't.
>
> If I view the source of the submission form, the tag is there and
> populated correctly - if I preview or submit an incorrect POST then it
> brings up the preview screen, but there isn't a hidden next field in
> there.
>
> If I submit a correctly formed comment, it brings up the "Thank you for
> your comment" template but doesn't redirect back to the original object.

I think that http://code.djangoproject.com/ticket/8968 has something to
do with your problem.
--
Happy Hacking.

http://sphinx.net.ru

Eric Abrahamsen

unread,
May 31, 2009, 2:30:30 AM5/31/09
to django...@googlegroups.com

On May 29, 2009, at 5:40 AM, Kevin Fullerton wrote:

>
>
> On Thu, May 28, 2009 14:31, Eric Abrahamsen wrote:
>>
>> The default comment form does not include a next parameter, so if you
>> don't override the builtin comment templates you won't get any next
>> parameters in the forms. The most sure way of doing this is using a
>> custom comment form with a next field – that way the form will
>> include
>> the field no matter where it is used in your project. Otherwise, you
>> can use custom comment form and preview form templates – I'm guessing
>> you originally didn't have a custom preview template, which meant it
>> was using the builtin one, which meant... no next parameter in the
>> html form.
>
> Looking at the django source the next parameter is included in the
> default
> preview template -
> http://code.djangoproject.com/browser/django/trunk/django/contrib/comments/templates/comments/preview.html
> line 9
>

Hmm, no kidding, not sure how I missed that. Dmitri's suggestion and
the linked ticket would work for a GET parameter "next", but for
previews and error corrections a simple form input value should work
(and does work, in my case). Have you tried getting rid of your GET
parameter value altogether, and only using the form input? Are you
doing anything else strange in comment submissions? Also, why are you
giving different next values in the GET parameter and the form input
value, below?

E
Reply all
Reply to author
Forward
0 new messages