Tuesday, November 29, 2011

Re: A view associated with a lot of urls

On Tue, Nov 29, 2011 at 2:19 PM, Nolhian <Eldurian@hotmail.com> wrote:
> Thanks you for your answer, yes I plan on using different models for
> the lookups. But I'm confused, is that a yes to my question, Lists/
> dicts are the way to go here ?

I would not do it that way. Seems incredibly brittle and you are
mixing up you model with your view (so to speak).

I would do it like so:

url(r'^(?P<category>\w+)/(?P<item>\w+)/?(?P<subitem>\w+)/', view,
name='complicated_view')

and then in the view:

def view(request, category, item, subitem=None):
MyModel.objects.get(category=category, item=item)

or whatever.

Then you could have urls that look like /computer/keyboard/ or
/animal/dog/Fido, etc

--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment