I have the following view that I want to only stay in the current view if it hasn't been redirected.
def surveys_view(request, survey=None):
if survey != 'survey1':
return redirect('matching:surveys', survey='survey1')
My urls.py looks like this:
url(r'^surveys', views.surveys_view, name='surveys'),
url(r'^surveys/(?P<survey>survey1|survey2)', views.surveys_view, name='surveys'),
The problem is that the survey variable is None every time causing infinite redirects. I would think that after the redirect, the survey value would be set to 'survey1'.
How can I have the survey parameter set to 'survey1' instead of None?
in django
urlslist is parsed from 0th position, so in your urls,has first priority, since the regular expression matches like any uri starting with
surveys<whatever>, so either change the url settings to,or change the order
NOTE: notice there is also change in name parameter, since it is better to be set as a unique value