Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
272 views
in Technique[技术] by (71.8m points)

django - How to pass full data as it is without getting converted via GET?

I'm trying to manipulate my form's action via js with the following code:

form.action = "{% url 'search.html' phrase='developer' %}"

The problem is, it converts my data to weird signs instead of passing it as it is.

http://localhost:8000/%7B%%20url%20'search.html'%20phrase='developer'%20%%7D?

How can I avoid this convertion ?

question from:https://stackoverflow.com/questions/65643510/how-to-pass-full-data-as-it-is-without-getting-converted-via-get

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The problem is, it converts my data to weird signs instead of passing it as it is.

No, it does not convert anything. It here simply uses {% url 'search.html' phrase='developer' %} as the real URL, and since a URL can not use {, %, etc. as characters, it uses percent encoding [wiki].

Indeed, if you use for example a tool like url-encode-decode, then you will see that it will decode this to {% url 'search.html' phrase='developer' %}.

The reason this happens is because you apparently do not render that part of the template. This is for example the case if you use a JavaScript file that you thus serve as a static file.

You thus should make sure that the {% url … %} part is located in the template: a file where the template engine will convert this to a URL, not in a (static) file where Django never passes this to the template engine.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...