[Flask] Having troubles with template rendering in class-based routing
ddwiggins at advpubtech.com
Wed Nov 25 15:56:48 EST 2015
I'm having trouble doing routing with class-based dispatching.
In my url_map, I have a rule: "<Rule '/Home/<name>' (HEAD, OPTIONS, GET)
The view_func set to:
> self.RenderTemplateView.as_view( self.label, self.label+'.html',
where self.label='Home', and there's a template in "templates/Home.html"
that renders differently depending on whether <name> has a value or is None.
RenderTemplateView is defined as:
> class RenderTemplateView(flask.views.View):
> def __init__(self, template_name, *args, **kwargs):
> self.template_name = template_name
> def dispatch_request(self, *args, **kwargs):
> return flask.render_template(self.template_name)
Call it with "http://127.0.0.1:5000/Home/thing" renders the template,
except that the <name> variable is bound to None, not to "thing". If I
add "name='thing' " to the render_template call, it does get included in
I've tried a number of things, including inserting a line "x = 1/0"
before the render_template call to get a traceback, then examining the
sequence of calls; I couldn't find anything helpful.
Decorator-based routing works fine, but isn't an option for me.
Any good words appreciated,
Advanced Publishing Technology
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Flask