Created
January 29, 2014 02:14
-
-
Save dirn/8680616 to your computer and use it in GitHub Desktop.
Direct to Template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def direct_to_template(blueprint, rule, template, **kwargs): | |
"""Return a view rendered directly from a template.""" | |
def f(template, **kwargs): | |
return render_template(template, **kwargs) | |
endpoint = kwargs.pop('endpoint', None) | |
if not endpoint: | |
endpoint = os.path.basename(template).split('.')[0] | |
blueprint.add_url_rule( | |
rule, | |
endpoint=endpoint, | |
view_func=f, | |
defaults={'template': template}, | |
**kwargs) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment