How to url encode in Django views

In Django, I want to do this

 <a href="{% url 'firstapp:create' %}?next={{ nextos|urlencode }}">

but in my views.py, when I render a page

return render(request, 'create' + parameter next=nextos)

Any ideas?


Solution 1:

I just had to do this myself. Ended up with this solution

from django.utils.http import urlencode
from django.http import HttpResponseRedirect

Then in your view:

 return HttpResponseRedirect( reverse('firstapp:create') + '?' + urlencode({'next': nextos }))

I hope that helps!
Nick