[Fixed]-One url for views with id and not with id

1👍

Sure, there is a way. Just make the token url parameter optional. Like this:

url(r'^users/(?P<token>[0-9a-z]+)?$', views.UserList.as_view(), name='user_profile'),

Notice the trailing ?, which means 0 or 1 matches of the token. If the token is provided then it’ll be the value provided (obviously!). If not, it will be None.

👤nik_m

Leave a comment