0

I have this in my template:

<div id="comment-{{ post_comment.id }}">
<a title="Comment was useful" href="/useful-comment/{{ blog_post.id }}/{{ post_comment.id }}/">

When the user clicks on this link, the method useful_comment(blog_post_id, post_comment_id) is called and at when it returns it loads the same template again. I then want to scroll the page down to #comment-{{ post_comment.id }}, but how do I do that if I load my template like so:

arguments = dict(user = request.user, blog_post = blog_post)

t = loader.get_template('blog-post-template.html')
c = RequestContext(request, args)
return HttpResponse(t.render(c))

This is related to Django: How do I position a page when using Django templates, but in that question they are using forms and only scrolling down to a static section of the page.

4

1 回答 1

0

You should add an #anchor to your link's href. In your case there will be different anchors (<a name="comment_123"></a>, for example) for all your comments, so be sure link points to correct anchor.

This is nothing to do with Django, just old good HTML.

于 2012-04-21T04:33:06.670 回答