Reputation: 272074
I am using Django.
In a regular form, the user enters "Gerry & Pacemakers".
(Notice the Ampersand sign.)
When I go views.py...
def myview(request):
q = request.GET.get('q','').strip()
print q
q is "Gerry"...but it's supposed to be "Gerry & Pacemakers"...encoded Is the correct way doing this by using urllib??
How do I encode it BEFORE it hits the view? It's very weird, because the URL contains the encoding: ?q=gerry+%26+pacemakers
Upvotes: 1
Views: 128
Reputation: 375744
Since you are pulling the data from request.GET, it looks like you're building the URL in the browser somehow. You need to use the Javascript escape()
function to handle URL-significant characters properly.
Upvotes: 2