python 2.7 - Flask partial view for a list of items -


if on pages in website have list of categories or recent articles loaded db - how can avoid duplicating code using flask , jinja2 ?

the way now, have html file include :

{% include '/root/latest_articles.html' %} 

and every view has pass parameter (list of articles) template. i'd avoid this.

what's best way achieve in flask?

thanks.

edit

the "additional template context" work .. export function loads data db , access in "latest_articles.html" template.

is there way ?

you can add additional template context:

@app.context_processor def additional_context():     return {         'content': get_page_content_context(request.endpoint, g.language),         'hot_links': get_hot_links(),     } 

for templates code can use macros or include.

upd:

at first try use template inheritance , put list of categories or recent articles in base template if pages allow this.

you can make template code variable `@app.context_processor', don't think it's idea:

@app.context_processor def additional_context():     return {         'recent_articles_markup': do_mark_safe(render_template(             'root/latest_articles.html', articles=get_recent_articles()),     } 

Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -