On Mon, 2006-09-25 at 07:22 -0700, xaranduu wrote: > I want to build a generic view for all of my objects and according to > the documentation > (http://www.djangoproject.com/documentation/url_dispatch/#captured-parameters) > it is possible to capture a parameter and forward it to the view . > > Target is to get completely automated generic views, without having to > edit any template > (maybe have a set of templates designed once, but valid for all > objects) > > So I dont want to pass the parameter to the template but to the second > urls.py > > > My approach would be more a kind of > > # In urls.py > urlpatterns = patterns('', > (r'^(?P<objecttype>\w+)/', include('foo.urls.mygenericurls')), > ) > > # In foo/urls/mygenericurls.py > > infodict = {} > > info_dict["myobject"] = { 'queryset': Myobject.objects.all(),} > info_dict["myotherobject"] = { 'queryset': > Myotherobject.objects.all(),} > > > urlpatterns = patterns('foo.genericviews', > (r'^list/$', 'blog.index', info_dict[objecttype]), > (r'^detail/$', 'blog.archive',info_dict[objecttype]), > ... > ) > > but the objecttype is not visible in the foo/urls/mygeneric.py but only > in the genericviews! > > Can anybody help
You can't do this directly in this fashion. The patterns(...) contents are not evaluated dynamically at runtime like this. Instead you need to write a small piece of Python code to work out the extra information to ultimately pass to the view. For Django's generic views, there is an example here: http://www.pointy-stick.com/blog/2006/06/29/django-tips-extending-generic-views/ Extending this to call your own views, rather than Django's views is straightforward. Regards, Malcolm --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~----------~----~----~----~------~----~------~--~---