将特殊字符从 django 传递到 views.py
Pass special characters from django to views.py
我正在尝试将字符串从 Html 页面传递到 views.py
字符串有一些特殊字符,字符串:
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;
我发现问题出在正则表达式的 urls.py 中。特殊字符'#'
后未传递字符串
urls.py :
(r'^bulkimport/importMedications/(?P<stringP>.+)', importMedications),
我也试过了
(r'^bulkimport/importMedications/(?P<stringP>[\w\+%_&\# ].+)', importMedications),
传递的字符串是:
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
如果我删除字符“#”,所有字符串都会被传递。
哈希标记#
是URL中的保留字符,它引入了fragment identifier。
要在 URL 中使用它,您必须 percent escape it as %23
. You can use urllib.quote 才能做到这一点。
但是,我强烈建议您尽可能使用 POST 请求来导入您的数据。
我对 GET 也有同样的问题。我无法传递“+”字符。我做了以下操作:
q_string = dict(x.split('=')
for x in request.META['QUERY_STRING'].split('&')
)
然后我用 q_string 代替 request.GET。
我正在尝试将字符串从 Html 页面传递到 views.py
字符串有一些特殊字符,字符串:
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;
我发现问题出在正则表达式的 urls.py 中。特殊字符'#'
后未传递字符串urls.py :
(r'^bulkimport/importMedications/(?P<stringP>.+)', importMedications),
我也试过了
(r'^bulkimport/importMedications/(?P<stringP>[\w\+%_&\# ].+)', importMedications),
传递的字符串是:
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
如果我删除字符“#”,所有字符串都会被传递。
哈希标记#
是URL中的保留字符,它引入了fragment identifier。
要在 URL 中使用它,您必须 percent escape it as %23
. You can use urllib.quote 才能做到这一点。
但是,我强烈建议您尽可能使用 POST 请求来导入您的数据。
我对 GET 也有同样的问题。我无法传递“+”字符。我做了以下操作:
q_string = dict(x.split('=')
for x in request.META['QUERY_STRING'].split('&')
)
然后我用 q_string 代替 request.GET。