Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django: How do I position a page when using Django templates

Tags:

django

I have a web page where the user enters some data and then clicks a submit button. I process the data and then use the same Django template to display the original data, the submit button, and the results. When I am using the Django template to display results, I would like the page to be automatically scrolled down to the part of the page where the results begin. This allows the user to scroll back up the page if she wants to change her original data and click submit again. Hopefully, there's some simple way of doing this that I can't see at the moment.

like image 648
FunLovinCoder Avatar asked Dec 13 '22 21:12

FunLovinCoder


1 Answers

It should already work if you provide a fragment identifier in the action method of the form:

<form method="post" action="/your/url#results">
    <!-- ...  -->
</form>

and somewhere below the form, where you want to show the results:

<div id="results">
    <!-- your results here -->
</div>

This should make the page jump to the <div> with ID results.

It is complete client site and does not involve Django, JavaScript or similar.

like image 70
Felix Kling Avatar answered May 26 '23 12:05

Felix Kling