I am trying to pass parameters to Django view but I couldn't decide what is the best way to do it.
I am making an AJAX call and my javascript code is
url = "/review/flag/code/"+ code +"/type/" + type + "/content/" + content + "/";
$.getJSON(url, somefunction);
The corresponding url for this call
(r'^rate/code/(?P<code>[-\w]+)/type/(?P<type>[-\w]+)/content/(?P<content>[-\w]+)/$', 'project.views.flag_review'),
And I can get the parameters in my view such that
def rate_review(request,code,type,content):
....
My question is because content
comes from a textarea
it may involve many escape chars and passing it like above causes problems due to regular expression.
Is there any way if I pass the parameters like www.xx.com/review/rate?code=1&type=2&content=sdfafdkaposdfkapskdf... ?
Thanks
If the content
variable is input through a textarea
input field in a form, you should probably be using the HTTP POST
method for submitting the data. You would get something like:
url = "/review/flag/code/"+ code +"/type/" + type;
$.post(url, {'content': content}, somefunction, 'html');
(r'^rate/code/(?P<code>[-\w]+)/type/(?P<type>[-\w]+)/$', 'project.views.flag_review'),
def rate_review(request,code,type):
content = request.POST['content']
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With