Django:关键字RegExp的搜索URL

2024-10-04 07:35:01 发布

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

我有以下网址:
http://127.0.0.1:8000/databaseadd/q=DQ-TDOXRTA?recipe=&recipe=&recipe=&recipe=&recipe=

我想匹配是否在url中找到关键字“recipe=”。
我在django有以下的线路网址.py但它不起作用:
url(r'recipe=', 'plots.views.add_recipe'),

是“&;”和“?”扔掉它?在

谢谢!
亚历克斯


Tags: djangopyaddhttpurlrecipe关键字database
2条回答

I'd like to match if the keyword "recipe=" is found in the url

你可以尝试一下:

import re;
re.match (r'.*recipe=.*', "http://127.0.0.1:8000/databaseadd/q=DQ-TDOXRTA?recipe=&recipe=&recipe=&recipe=&recipe=")

?之后的部分未在url调度过程中使用,因为它包含GET参数。否则,您将无法使用带有参数的GET请求,比如r'^foo/&'(末尾的和号表示字符串的结尾,没有它,将很难同时使用r'^foo/'和{}等模式)。在

因此对于您的url,模式应该看起来像r'^databaseadd/q=DQ-TDOXRTA&',然后在add_recipe视图中,您需要检查recipeGET参数。在

相关问题 更多 >