I think you'll have to try implementing it to see if it's feasible.

On Thursday, June 4, 2015 at 5:44:54 AM UTC-4, erez....@gmail.com wrote:
>
> Hi, 
>
> AFAIK, the recommended way in Django to handle multiple urls with the same 
> view, is to have optional parameters. (
> https://docs.djangoproject.com/en/1.8/topics/http/urls/#specifying-defaults-for-view-arguments
> )
>
> For example,
>
> in url.py:
>
> url(r'^blog/page/(?P<page_pk>\d+)/$', views.page, name='view-page'),
> url(r'^blog/page/(?P<page_pk>\d+)/(?P<page_slug>[a-zA-Z0-9_.-])/$', views.
> page, name='view-page'),
>
> in views.py:
> # View (in blog/views.py)
> def page(request, page_pk, page_slug=""):
>
>
> However, in the templates, the url template tag can't accept optional 
> parameters.
> So instead of writing {% url 'view-page' page_pk page_slug %}, you need to 
> write {% if page_slug=="" %}{% url 'view-page' page_pk %}{% else %}{% url 
> 'view-page' page_pk page_slug %}{% endif %}
> On the project I'm working on I have 2 or more optional parameters, and 
> it's a real nuisance.
>
> The url tag could have done this logic by itself. If any of its inputs are 
> blank or none, disregard it.
>
> Same question from Stack Overflow (not asked by me) : 
> http://stackoverflow.com/questions/16870884/url-template-optional-param
>
> Thanks
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
Visit this group at http://groups.google.com/group/django-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/9c67b646-ee16-4f82-a545-9e4178d4e7dc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to