def render_with_dict(template):
    mydict = code_to_generate_dict()
return render_template(template, mydict=mydict)

def myview():
    return render_with_dict('main_page.html')
Pass variables to all Jinja2 templates with Flask