On 10-08-11 11:20, samuele.mattiuzzo wrote:

url(/<country>/, search_view),
url(/<city>/, search_view),
url(/<country>/<city>/, search_view)

as you can see, case 1 and case 2 are a trouble: country and city are
both strings, how's the url supposed to know if a link pointed to one
url or another? Should i use named views in templating? What's the
best way i can use them in my case?

You could make it more explicit:

url(/country/<country>/, search_view),
url(/city/<city>/, search_view),
url(/country/<country>/<city>/, search_view)

So prefix all country urls with 'country/' and cities likewise.


You could, if you like the "/italy/rome" style of urls more, also make an exception just for cities (but *do* place that exception at the top):

url(/city/<city>/, search_view),
url(/<country>/, search_view),
url(/<country>/<city>/, search_view)

So only cities are prefixed with "city/" to distinguish them.


And you'd better use named variables, so

/(?P<country>.*)/

instead of

/<country>/

(unless you meant that already in your shorthand form, of course).

The view function then can have keyword arguments:

def search_view(request, country=None, city=None)



Reinout

--
Reinout van Rees                    http://reinout.vanrees.org/
rein...@vanrees.org             http://www.nelen-schuurmans.nl/
"If you're not sure what to do, make something. -- Paul Graham"

--
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.

Reply via email to