简体   繁体   中英

How to load a page starting at a specific section ID, using template.render() using python, jinja2

Here's the python code:

template = jinja_environment.get_template('index.html')
self.response.out.write(template.render(template_values))

However, I'd like to load index.html starting at the anchor tag below:

(wherein this anchor tag is in the index.html file)

<section> id="home">

How would i change the python code to do this?

As you can tell, I'm new, and currently working through the Google App Engine tutorials.

Thanks for your help!

I think that you are a bit confused. With jinja2 and Python code all you can achieve is to produce the page server-side. If you want to jump into a specific section within that page you should do that client-side by using JavaScript ( example ).

Let's supose you want acces your page at /yourpage and on home section. You could do this with a redirect:

YourHandler(RequestHandler):
    def get(self):
        self.redirect("/yourpage#home")

So you need to put the section id just after the "#" sign.

It worked for me at least on Google Chrome.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM