Skip to content

Instantly share code, notes, and snippets.

@dirn
Created January 29, 2014 02:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dirn/8680616 to your computer and use it in GitHub Desktop.
Save dirn/8680616 to your computer and use it in GitHub Desktop.
Direct to Template
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