Django comment, add character to comment url?

im using the comment system, now I would like to rewrite a fragment of the url comment form and add the # character, I want to move the seccion page to the comment list exactly to the last comment user with <a name=#{{comment.id}}?> username </a>

I use the following to redirect usen when a comment has been posted:

{% get_comment_form for object as form %}
<form action="{% comment_form_target %}" method="POST">
  {{ form }}
  <input type="hidden" name="next" value="{{ object.get_absolute_url }}" />
  <input type="submit" name="preview" class="submit-post" value="Preview"></td>  
</form>

But the Django Doc doesn't say anything about rewriting or setting up a redirect / url comment

Any idea?

thanks

+3
source share
1 answer

. . URL- {{ next }}, Django ?c=1 URL-, 1 . , #c1, , . " " :

from django.contrib.comments.views import utils
from django.core import urlresolvers
from django.http import HttpResponseRedirect

def next_redirect(data, default, default_view, **get_kwargs):
    next = data.get("next", default)
    if next is None:
        next = urlresolvers.reverse(default_view)
    if get_kwargs:
        next += '#c%d' % (get_kwargs['c'],)
    return HttpResponseRedirect(next)

# Monkey patch
utils.next_redirect = next_redirect
+5

Source: https://habr.com/ru/post/1718234/


All Articles