[Flask] Question on Pluggable Views

Lars Peter Søndergaard lps at chireiden.net
Mon May 9 16:27:10 EDT 2016


On Mon, 9 May 2016 10:55:01 -0700 Don Dwiggins
<ddwiggins at advpubtech.com> wrote:

> Has anyone here used pluggable views, as described in 
> http://flask.pocoo.org/docs/0.10/views/ ?
> 
> I'm curious about the role of the first argument to the "as_view"
> method of the View class.  In the last example of the Basic Principle
> section, the text states " The class itself is instantiated with the
> parameters passed to the as_view() function.", but in the example,
> template_name is the only parameter to __init__; the first parameter
> to as_view, 'about_page', doesn't seem to be used.
> 
> Experimenting a bit, I find that this first parameter needs to be 
> present, and must be a string -- that's all.  Actually, it's the 
> parameters after the first that get passed to the __init__ method.
> 
> In my code, I'm using an empty string for it in all cases, and it 
> appears to work well.  However, I have a nagging feeling that this
> first parameter ought to be useful for something.
> 
> Any good thoughts welcome,

The first arg "name" is used by the as_view classmethod itself. Any
other argument that follows is used to instantiate the class.

https://github.com/pallets/flask/blob/0.10.1/flask/views.py#L73

The "name" is the name of the endpoint. You should always specifiy it.
It's the name you use, when you build URLs using the url_for() function.

-- 
nitori
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 819 bytes
Desc: OpenPGP digital signature
URL: <http://mail.python.org/pipermail/flask/attachments/20160509/627a9495/attachment.sig>


More information about the Flask mailing list