python - Jinja2 render multiple html files? -


i have main index.html file , contains several links sub-html files. example, index.html if user clicks link directs sub-page intro.html seems render_template receives 1 html file. how connect multiple html files using render_template?


files structures: templates/ index.html text.html

i want link text.html file index.html.

in index.html, have link following:

<a href="text.html">link</a> 

then want direct link load contents of text.html


second edit

@app.route('/myhtml', methods=['get']) def myhtml():     return render_template('myhtml.html') 

i want to this. if type localhost:8000/myhtml should link myhtml.html

it's pretty easy-- need capture file you're requesting url, use existing template:

from flask import flask, render_template, abort jinja2 import templatenotfound app = flask(__name__)  @app.route('/', defaults={'page': 'index'}) @app.route('/<page>') def html_lookup(page):     try:         return render_template('{}.html'.format(page))     except templatenotfound:         abort(404)  if __name__ == '__main__':     app.run() 

if try access 127.0.0.1:5000 it'll default page variable index , therefore try , render_template('index.html') whereas if try 127.0.0.1:5000/mypage instead search mypage.html.

if fails, it'll abort 404 not found error.

this example, totally cribbed simple blueprint example in flask documentation.


Comments

Popular posts from this blog

Error while updating a record in APEX screen -

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

ios - Xcode 5 "No such file or directory" -