Django: how to place a page when using Django templates?

I have a webpage where the user enters some data and then clicks the submit button. I process the data and then use the same Django template to display the source data, submit button and results. When I use the Django template to display the results, I would like the page to automatically scroll to the part of the page where the results begin. This allows the user to scroll through the backup page if she wants to change the original data and send the request again. Hopefully there is an easy way to do this that I don't see at the moment.

+4
source share
2 answers

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

<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 will cause the page to jump to a <div> with the id of results .

This is a complete client site and does not include Django, JavaScript or the like.

+11
source

You need to wrap your data like this:

 <div id="some-id">YOUR DATA TO BE DISPLAYED</div> 

and if you do a redirect in your view, you need to redirect the url: /some-url/#some-id

If you are not doing the redirection, you need to scroll through the bottom using javascript (but note that redirecting is recommended when saving data).

+1
source

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


All Articles