2024-10-04 07:35:01 发布
网友
我有以下网址: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'),
http://127.0.0.1:8000/databaseadd/q=DQ-TDOXRTA?recipe=&recipe=&recipe=&recipe=&recipe=
url(r'recipe=', 'plots.views.add_recipe'),
是“&;”和“?”扔掉它?在
谢谢! 亚历克斯
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/'和{}等模式)。在
?
r'^foo/&'
r'^foo/'
因此对于您的url,模式应该看起来像r'^databaseadd/q=DQ-TDOXRTA&',然后在add_recipe视图中,您需要检查recipeGET参数。在
r'^databaseadd/q=DQ-TDOXRTA&'
add_recipe
recipe
你可以尝试一下:
?
之后的部分未在url调度过程中使用,因为它包含GET参数。否则,您将无法使用带有参数的GET请求,比如r'^foo/&'
(末尾的和号表示字符串的结尾,没有它,将很难同时使用r'^foo/'
和{因此对于您的url,模式应该看起来像
r'^databaseadd/q=DQ-TDOXRTA&'
,然后在add_recipe
视图中,您需要检查recipe
GET参数。在相关问题 更多 >
编程相关推荐