Reputation: 67
I am trying to pass a string from an Html page to views.py
The string has some special characters, string:
Clarithromycin 500 MG Extended Release Tablet;http://purl.bioontology.org/ontology/RXNORM/;259543;9/4/2010;2;d;1 bid;Prescription;http://smartplatforms.org/terms/codes/MedicationProvenance#;prescription ;1;{tablet} ;7/7/2014;2007-10-03 03:00:00+03;
I have found that the problem is in urls.py in regex expression. The string is not passed after special character '#'
urls.py :
(r'^bulkimport/importMedications/(?P<stringP>.+)', importMedications),
I have also tried
(r'^bulkimport/importMedications/(?P<stringP>[\w\+%_&\# ].+)', importMedications),
and the passed string is:
Clarithromycin 500 MG Extended Release Tablet;http:/purl.bioontology.org/ontology/RXNORM/;259543;9/4/2010;2;d;1 bid;Prescription;http:/smartplatforms.org/terms/codes/MedicationProvenance
If I remove character '#' all the string is passed.
Upvotes: 1
Views: 1382
Reputation: 1075
I had the same issue with GET. I could not pass '+' character. I did following:
q_string = dict(x.split('=')
for x in request.META['QUERY_STRING'].split('&')
)
And then I used q_string instead request.GET.
Upvotes: 5
Reputation: 29967
The hash mark #
is a reserved character in URLs, it introduces the fragment identifier.
To use it in a URL, you have to percent escape it as %23
. You can use urllib.quote to do that.
However, I would strongly advise you to use POST requests to import your data, if possible.
Upvotes: 0