snakile
snakile

Reputation: 54521

Django Comments app: How do I disable the redirection to posted.html?

I'm using Django's comments framework. Whenever someone posts a comment he is redirected to a success page (posted.html). I don't want a success page to show up. I just want the current page to be reloaded (with the new comment on it). How do I stop the redirection?

Upvotes: 2

Views: 2080

Answers (2)

stephrdev
stephrdev

Reputation: 191

Adding a hidden form field named next is the way to go, but you should use request.get_full_path because request.path doesn't include query strings:

<input type="hidden" name="next" value="{{ request.get_full_path }}" />

Upvotes: 6

Brandon Taylor
Brandon Taylor

Reputation: 34573

From looking through the source in: contrib.comments.views.comments, it looks like you can supply a "next" parameter to override the where the redirect goes.

#django.contrib.comments.views.comments

@csrf_protect
@require_POST
def post_comment(request, next=None, using=None):

    #more code here...

    # Check to see if the POST data overrides the view's next argument.
    next = data.get("next", next)

    #more code here...

I would try adding a hidden field to the comment form with a name of "next" and a value of the current url you're on. If that doesn't work, you might have to supply your own view and url. Hope that works!

Upvotes: 1

Related Questions