Wichert Akkerman wrote:
> The current bfg docs do not seem to explain add_route very well. The URL
> dispatch section briefly mentions its existance, but does not show
> anything beyond a very trivial usage.
> Trying to use it it seems that you
> have to pass a Python callable directly as view parameter, instead of a
> reference to a callable as the docstring for add_route seems to imply.
> Note that I am interpreting 'reference to' as a dotted path, since
> otherwise you would not be using a reference but the actual thing.
It meant a reference in the Python sense, sorry.
> is a bit awkward since it means you have to import all your view code
> from run.py. Would it be possible to support dotted paths in add_route
> (and thus add_view as well)?
To be honest, I don't think so, because a) this is the very lowest level of
configuration, adding DWIM here doesn't feel quite right and b) it's already
plain old imperative Python so you can do whatever you want anyway.
If you don't want to import anything, and you want dotted-name-string
resolution magic here, especially for routes config, I'd either:
- just put the routing config in ZCML and load it.
- write a function that does the dotted-name-string resolution and use it
within add_view/add_route, e.g. add_route(..., view=resolve('foo.bar')).
> Relatedly it seems there is a flaw in the add_view example in the views
> chapter. It has this example:
> config.add_view(name='my_view', request_method='POST', for_=MyModel,
> which is missing the view parameter.
Repoze-dev mailing list