Hi, I am trying to use a series of generic views with custom filtering via callbacks as per:
http://docs.djangoproject.com/en/dev/topics/generic-views/#extending-generic-views Unfortunately, when I try to name the URL in urls.py, I get various errors depending upon how I try to write the pattern call. I'll write a skeleton of what the code really is: ___________ in views.py: - - - - - - - - - - - - - - def my_filter_callback(request, name): ... return list_detail.object_list( request, queryset... ) ___________ in my_template.html: - - - - - - - - - - - - - - {% for object in obects_list %} <a href="{% url url-pattern-name name=object.name %}/"> {{ object.name }}</a> {% endfor %} ___________ in urls.py: - - - - - - - - - - - - - - from views import my_filter_callback urlpatterns += patterns( '', ( r'path/(P?<name>[\w\d-]+)/?$', my_filter_callback, 'url-pattern- name'), ) - - - - - - - - - - - - - - AttributeErrror: 'str' object has no attribute 'resolve' /opt/local/Library/Frameworks/Python.framework/Versions/2.5/lib/ python2.5/site-packages/django/core/urlresolvers.py in resolve 211. def resolve(self, path): 212. tried = [] 213. match = self.regex.search(path) 214. if match: 215. new_path = path[match.end():] 216. for pattern in self.url_patterns: 217. try: 218. sub_match = pattern.resolve(new_path) ___________ in urls.py: - - - - - - - - - - - - - - from views import my_filter_callback urlpatterns += patterns( '', ( r'path/(P?<name>[\w\d-]+)/?$', my_filter_callback, 'url-pattern- name'), ) - - - - - - - - - - - - - - ValueError at /path/ dictionary update sequence element #0 has length 1; 2 is required /opt/local/Library/Frameworks/Python.framework/Versions/2.5/lib/ python2.5/site-packages/django/core/urlresolvers.py in resolve 116. # positional arguments. 117. kwargs = match.groupdict() 118. if kwargs: 119. args = () 120. else: 121. args = match.groups() 122. # In both cases, pass any extra_kwargs as **kwargs. 123. kwargs.update(self.default_args) ___________ Alternate version of urls.py urlpatterns += patterns( '', ( r'path/(P?<name>[\w\d-]+)/?$', my_filter_callback ), ) # note: after reading the code, I also passed the prefix "myapp.views", # then called my callback as "my_filter_callback", trying to get # the 'url' method of /django/conf/urls/defaults.py to compose # the callback path as a string. - - - - - - - - - - - - - - TemplateSyntaxError at /path/ Caught an exception while rendering: Reverse for 'url-pattern-name' with arguments '()' and keyword arguments '{'name': u'some-name'}' not found. ___________ So, I followed the source and tried a few different things. For example, I have tried to call RegexURLPattern adding a 'name' parameter, but that then gets passed to my callback, which in turn gets passed to django's generic list architecture. That subsequently generates an "unexpected attribute" error named "name", instead of it being used by RegexURLPattern to name the url pattern for reverse. Am I going to have to sub-class RegexURLPattern and force it to stick the name 'somewhere' appropriate, because at this point I don't think things are working as they should and I think I've dug deep enough to see that I've been making the correct calls. So, in a word: Help! Thanks in advance to any and all that can help me decode this mystery. Scott PS. My other alternative is to not reverse the URL, but calculate it m'self, which is less flexible. It may, in the short term be substantially quicker than some of my other alternatives. --~--~---------~--~----~------------~-------~--~----~ 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---