I want to have a model view with an optional argument that's specified by the model's get_absolute_url. This argument is None if the model's page is accessed by the user typing in the URL in his browser, while the argument is set to some value if the model's page is accessed by clicking on a link such as the "View on site" button in the admin site.
This is what I came up with first: The model: class MyModel(models.Model): ... @models.permalink def get_absolute_url(self): return ('mymodels.views.model_view', (), { 'a': self.some_field, 'b': self.another_field, 'c': something_else_again } ) The URLConf: (r'^(?P<a>[-\w]+)/(?P<b>[-\w]+)/$', 'model_view') The view: def model_view(request, a, b, c = None): if c: # Do something else: # Do something else Accessing the model's page by just typing in a URL works (where c is None). However, accessing the model's page by, say, clicking "View on site" in the admin (where c should be set to the model type's ID) gives me this NoReverseMatch error: NoReverseMatch at /admin/r/<xy>/<z>/ Reverse for '<function model_view at 0x...>' with arguments '()' and keyword arguments '{'a': u'something', 'b': u'something-else', 'c': 'something-else-again'}' not found. Exception location: C:\Python26\lib\site-packages\django\core \urlresolvers.py in reverse, line 291 What is the proper way to introduce optional arguments here? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---