将特殊字符从Django传递到视图.py

2024-10-03 06:24:06 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试将一个字符串从Html页传递到视图.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;

我发现问题出在网址.py在正则表达式中。字符串不在特殊字符“#”之后传递

在网址.py公司名称:

^{pr2}$

我也试过了

  (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

如果我删除字符“#”,则所有字符串都将被传递。在


Tags: 字符串pyorgextendedhttpreleaseontologypurl
2条回答

我也有同样的问题。我不能传递'+'字符。我做了以下工作:

q_string = dict(x.split('=')
    for x in request.META['QUERY_STRING'].split('&')
)

然后我用了q嫒请求.GET. 在

哈希标记#是url中的保留字符,它引入了fragment identifier。在

要在URL中使用它,您必须percent escape将其命名为%23。您可以使用urllib.quote来执行此操作。在

但是,如果可能的话,我强烈建议您使用POST请求来导入数据。在

相关问题 更多 >