So simple. I need to re-learn the RTFM rule.
i just need to do a import like:
from werkzeug import import_string
map may urls like:
url_map = Map([
Rule('/', endpoint='myapp.module1.views.list')
])
and in my application.py:
( ... )
endpoint, values = adapter.match()
view = import_string(endpoint)
response = view(request, **values)
( ... )
ty
On 3 dez, 08:35, Khaoz <[EMAIL PROTECTED]> wrote:
> I'm trying to avoid to have 3 (or more) import lines.
> And on your example, getattr will need to be done on every view to
> find the exact endpoint.
>
> But will try to use something like:
>
> url_map = Map([
> Rule('/', endpoint='myapp.module1.views.list')
> ])
>
> I will make some testes tonight.
>
> On 2 dez, 22:24, Josh <[EMAIL PROTECTED]> wrote:
>
> > errm, I think that might need to be
>
> > handler = getattr(mod1views, 'endpoint')
>
> > (note the quotes around 'endpoint')...
>
> > On Dec 2, 6:23 pm, Josh <[EMAIL PROTECTED]> wrote:
>
> > > When I'm in such a situation, I do something like this:
>
> > > from myapp.module1 import views as mod1views
> > > from myapp.module2 import views as mod2views
> > > from myapp.module3.module4 import views as mod4views
>
> > > ...and later in your code, just do something like
>
> > > mod1views.special_view()
> > > mod2views.awesome_view()
> > > mod4views.crummy_view()
>
> > > similarly, if you really want to use "getattr", you should be able to
> > > do something like this
>
> > > handler = getattr(mod1views, endpoint)
>
> > > (hopefully I understood what you were asking about and responded
> > > satisfactorily.
>
> > > On Dec 2, 6:11 pm, Khaoz <[EMAIL PROTECTED]> wrote:
>
> > > > My project structure will have the following structure:
>
> > > > myapp.module1.views
> > > > myapp.module2.views
> > > > myapp.module3.module4.views
>
> > > > And growing ...
>
> > > > I will use the @expose decorator to keep the url mapping with the
> > > > actions in views.
>
> > > > How to avoid to import a lot of views, line by line ?
>
> > > > And how to do this:
>
> > > > handler = getattr(views, endpoint)
>
> > > > With diferent views ?
>
> > > > Ty
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"pocoo-libs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/pocoo-libs?hl=en
-~----------~----~----~----~------~----~------~--~---