flask_velox.mixins.template

Module provides mixins for rendering templates using Flask MethodView.

Example

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
from flask import Flask
from flask.ext.velox.mixins.template import TemplateMixin
from flask.views import MethodView

app = Flask(__name__)

class MyView(TemplateMixin):
    template = 'templates/home.html'

app.add_url_rule('/', view_func=MyView.as_view('myview'))

app.run()
class flask_velox.mixins.template.TemplateMixin

Bases: flask.views.MethodView

Renders a template on HTTP GET request as long as the template attribute is defined.

template str

Relative template path, e.g: templates/home.html

Example

1
2
class MyView(TemplateMixin):
    template = 'templates/home.html'
__getattr__(name)

Overriding this allows us to access request view args as attributes on view instances.

Returns:Attribute value
Return type:anything
Raises:AttributeError – If attribute does not exist
_template

Returns the defined template which should be set using the template attribute on classes inheriting this view.

Returns:Relative template path, e.g: templates/home.html
Return type:str
Raises:NotImplementedError – If self.template attribute is not defined
get(*args, **kwargs)

Handle HTTP GET requets using Flask MethodView rendering a single html template.

Returns:Rendered template
Return type:str
render()

Renders a template. This method will attempt to pass context to the template but if the context attribute does not exist then an empty dict will be passed to the render_template method.

Returns:Rendered template
Return type:str

http://thisissoon.com

Related Topics

This Page