BrA*_*ria 1 python regex django-urls special-characters
我正在尝试将字符串从 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;
Run Code Online (Sandbox Code Playgroud)
我发现问题出在正则表达式中的 urls.py 中。特殊字符“#”后不传递字符串
网址.py:
(r'^bulkimport/importMedications/(?P<stringP>.+)', importMedications),
Run Code Online (Sandbox Code Playgroud)
我也试过
(r'^bulkimport/importMedications/(?P<stringP>[\w\+%_&\# ].+)', importMedications),
Run Code Online (Sandbox Code Playgroud)
和传递的字符串是:
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
Run Code Online (Sandbox Code Playgroud)
如果我删除字符 '#' 所有的字符串都会被传递。
我对 GET 有同样的问题。我无法传递“+”字符。我做了以下:
q_string = dict(x.split('=')
for x in request.META['QUERY_STRING'].split('&')
)
Run Code Online (Sandbox Code Playgroud)
然后我用 q_string 代替 request.GET。