TIMEX
TIMEX

Reputation: 272074

After submitting form, the value is different due to encoding? (Python)

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

Answers (1)

Ned Batchelder
Ned Batchelder

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

Related Questions