Url with optional arguments

22 views
Skip to first unread message

cjacq...@gmail.com

unread,
Nov 8, 2017, 8:01:10 AM11/8/17
to Django users
Hi everyone,

I would like to make a documentation app with urls like this (not flatpages) :

[server]/docs/<product_slug>/ ==> go to product main help page

[server]/docs/<product_slug>/<subpage_slug>/ ==> go to product sub help page.

How can i write this in app urls.py ?

Thanks !


Avraham Serour

unread,
Nov 8, 2017, 8:19:48 AM11/8/17
to django-users
I recommend putting two entries on urls.py, they can both point to the same view.
Just be sure to set a default value for subpage_slug on the function argument

--
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+unsubscribe@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/3d4f0a0d-dc46-488a-9aec-a97120518e64%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

cjacq...@gmail.com

unread,
Nov 8, 2017, 8:28:06 AM11/8/17
to Django users
Thanks for your answer. =)

Yes, i tried :

import views

urlpatterns = [
url(r'^(?P<product_slug>[\w-]+)/$', views.DocPageDetail.as_view()),
url(r'^(?P<product_slug>[\w-]+)/(?P<subpage_slug>\w+)/$', views.DocPageDetail.as_view())
]


But second url pattern (with two arguments) is never found... :'(


Le mercredi 8 novembre 2017 14:19:48 UTC+1, Avraham Serour a écrit :
I recommend putting two entries on urls.py, they can both point to the same view.
Just be sure to set a default value for subpage_slug on the function argument
On Wed, Nov 8, 2017 at 3:01 PM, <cjacq...@gmail.com> wrote:
Hi everyone,

I would like to make a documentation app with urls like this (not flatpages) :

[server]/docs/<product_slug>/ ==> go to product main help page

[server]/docs/<product_slug>/<subpage_slug>/ ==> go to product sub help page.

How can i write this in app urls.py ?

Thanks !


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

Yue Du

unread,
Nov 8, 2017, 8:36:02 AM11/8/17
to django...@googlegroups.com

cjacq...@gmail.com

unread,
Nov 8, 2017, 8:41:53 AM11/8/17
to Django users
I found what happened : i make test with a "-" in the subpage_slug ...

Without it, all is working. :D
Reply all
Reply to author
Forward
0 new messages