URL design

27 views
Skip to first unread message

Горобец Дмитрий

unread,
Jun 3, 2016, 2:09:49 PM6/3/16
to Django users
Hello, guys.

I have the following URL patterns in my urls.py module and I'd like to refactor them:
url(r'^(?P<location_alias>[a-zA-Z0-9_\-]+)/(?P<category_alias>[a-zA-Z0-9_\-]+)/$', views.item_list, name="item_location_category"),
url(r'^(?P<location_alias>[a-zA-Z0-9_\-]+)/(?P<category_alias>[a-zA-Z0-9_\-]+)/(?P<property_one>[a-zA-Z0-9_\-]+)/$', views.item_list),
url(r'^(?P<location_alias>[a-zA-Z0-9_\-]+)/(?P<category_alias>[a-zA-Z0-9_\-]+)/(?P<property_one>[a-zA-Z0-9_\-]+)/(?P<property_two>[a-zA-Z0-9_\-]+)/$', views.item_list),
url(r'^(?P<location_alias>[a-zA-Z0-9_\-]+)/(?P<category_alias>[a-zA-Z0-9_\-]+)/(?P<property_one>[a-zA-Z0-9_\-]+)/(?P<property_two>[a-zA-Z0-9_\-]+)/(?P<property_three>[a-zA-Z0-9_\-]+)/$', views.item_list),
url(r'^(?P<location_alias>[a-zA-Z0-9_\-]+)/(?P<category_alias>[a-zA-Z0-9_\-]+)/(?P<property_one>[a-zA-Z0-9_\-]+)/(?P<property_two>[a-zA-Z0-9_\-]+)/(?P<property_three>[a-zA-Z0-9_\-]+)/(?P<property_four>[a-zA-Z0-9_\-]+)/$', views.item_list),
url(r'^(?P<location_alias>[a-zA-Z0-9_\-]+)/(?P<category_alias>[a-zA-Z0-9_\-]+)/(?P<property_one>[a-zA-Z0-9_\-]+)/(?P<property_two>[a-zA-Z0-9_\-]+)/(?P<property_three>[a-zA-Z0-9_\-]+)/(?P<property_four>[a-zA-Z0-9_\-]+)/(?P<property_five>[a-zA-Z0-9_\-]+)/$', views.item_list),
url(r'^(?P<location_alias>[a-zA-Z0-9_\-]+)/(?P<category_alias>[a-zA-Z0-9_\-]+)/(?P<property_one>[a-zA-Z0-9_\-]+)/(?P<property_two>[a-zA-Z0-9_\-]+)/(?P<property_three>[a-zA-Z0-9_\-]+)/(?P<property_four>[a-zA-Z0-9_\-]+)/(?P<property_five>[a-zA-Z0-9_\-]+)/$', views.item_list),
url(r'^(?P<location_alias>[a-zA-Z0-9_\-]+)/(?P<category_alias>[a-zA-Z0-9_\-]+)/(?P<property_one>[a-zA-Z0-9_\-]+)/(?P<property_two>[a-zA-Z0-9_\-]+)/(?P<property_three>[a-zA-Z0-9_\-]+)/(?P<property_four>[a-zA-Z0-9_\-]+)/(?P<property_five>[a-zA-Z0-9_\-]+)/(?P<property_six>[a-zA-Z0-9_\-]+)/$', views.item_list),
url(r'^(?P<location_alias>[a-zA-Z0-9_\-]+)/(?P<category_alias>[a-zA-Z0-9_\-]+)/(?P<property_one>[a-zA-Z0-9_\-]+)/(?P<property_two>[a-zA-Z0-9_\-]+)/(?P<property_three>[a-zA-Z0-9_\-]+)/(?P<property_four>[a-zA-Z0-9_\-]+)/(?P<property_five>[a-zA-Z0-9_\-]+)/(?P<property_six>[a-zA-Z0-9_\-]+)/(?P<property_seven>[a-zA-Z0-9_\-]+)/$', views.item_list)

Example:
http://mysite.com/london/cars/
http://mysite.com/london/cars/new/
http://mysite.com/london/cars/new/audi/
http://mysite.com/london/cars/new/audi/a4/
http://mysite.com/london/cars/new/audi/a4/2016/
http://mysite.com/london/cars/new/audi/a4/2016/white/ etc...

And it shouldn't be query parameter.

Does anyone have any suggestions?

Thank you.

Luis Zárate

unread,
Jun 3, 2016, 9:27:38 PM6/3/16
to django...@googlegroups.com
I can test this right now but based in my experience in re I think could be like this

url(r'^(?P<location_alias>[a-zA-Z0-9_\-]+)/(?P<category_alias>[a-zA-Z0-9_\-]+)/(?P<properties>([a-zA-Z0-9_\-]+)/){7})$', views.item_list)

Be worry with / in views
> --
> You received this message because you are subscribed to the Google Groups "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
> To post to this group, send email to django...@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/123e209e-3921-4399-affc-be8b4c67c6d9%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

--
"La utopía sirve para caminar" Fernando Birri



Reply all
Reply to author
Forward
0 new messages