Reputation: 2153
I have a Django CreateView that is supposed to redirect to a URL with a UUID in the querystring:
@method_decorator(xframe_options_exempt, name='dispatch')
class ActivityCreateView(CreateView):
template_name = 'embedded/activities/create.html'
form_class = ActivityCreateUpdateForm
def get_success_url(self):
return reverse_lazy('embedded:activity_status', kwargs={'unieke_code': self.object.access_link})
This however gives the familiar error:
Reverse for 'activity_status' with arguments '()' and keyword arguments '{'unieke_code': UUID('470e3a5f-6f52-414e-a431-bf5c6e68509a')}' not found. 1 pattern(s) tried: ['embedded/activiteiten/status/']
The weird thing is that it apparently finds the pattern, but still doesn't match. This is my urls.py:
urlpatterns = [
url(r'^activiteiten/$', views.ActivitiesIndexView.as_view(), name='activities_index'),
url(r'^activiteiten/aanmelden/$', views.ActivityCreateView.as_view(), name='activity_create'),
url(r'^activiteiten/status/', views.ActivityStatusView.as_view(), name='activity_status'),
]
Strangely enough when I go to mysite.com/embedded/activiteiten/status/?unieke_code=470e3a5f-6f52-414e-a431-bf5c6e68509a
it does work.
Upvotes: 0
Views: 492
Reputation: 350
The reverse and reverse_lazy functions are not intended for passing GET parameters. That's the reason why it's failing.
Something like this should work:
url = reverse_lazy('embedded:activity_status')
params = urlencode({'unieke_code': self.object.access_link})
return '{0}?{1}'.format(url, params)
Side note: In Python 2 you should import urlencode from urllib, and in Python 3, it's in urllib.parse
Upvotes: 2