Alessandro Ronchi wrote:
> I want to make a regxep in my urls.py that takes the name of the view from
> the url.
> Something like:
>
>
> (r'^views/(?P<name>\w+)/', 'myproject.database.reports.' + name),
>
> is it possible? I've a lot of views with the same rule and I want to make
> them be available without duplicate names 3 or 4 times.
It seems the way to do this would be through a dispatcher view.
Something like this untested code:
import myproject.database.reports as reports
dev report_dispatcher(request, name):
if hasattr(reports, name):
fn = getattr(reports, name)
return fn(request)
raise Http404
then just wire your URL dispatcher to this view
(r'^views/(?P<name>[a-zA-Z]\w*)/', report_dispatcher),
-tim
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" 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/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---