需要干草堆登录(Haystack login required)
我正在使用Haystack默认URLConf来设置视图。 因此:
(r'^search/', include('haystack.urls')),
我如何将它包装在login_required装饰器中,因为我只希望登录用户访问搜索。 谢谢。
I am using Haystack default URLConf to setup the views. As such:
(r'^search/', include('haystack.urls')),
How would I wrap it in a login_required decorator, since I only want logged in users to access the search. Thank you.
原文:https://stackoverflow.com/questions/14694754
最满意答案
正则表达式模式必须以可选参数开始和结束。 此外,不要忘记逃离你模式中的所有特殊字符。
$pattern = '/<p class="productprice"><strong>from ([0-9]+.*) EUR<\/strong><\/p>/';
你可以使用Regexr之类的东西来测试你的模式。 我在这里为您创建了一个: http : //regexr.com/3f173
A regex pattern has to start and end with
/
followed by optional parameters. Also, don't forget to escape all special characters in your pattern.$pattern = '/<p class="productprice"><strong>from ([0-9]+.*) EUR<\/strong><\/p>/';
You can use something like Regexr to test your patterns. I have created one for you here: http://regexr.com/3f173
相关问答
更多-
PHP 正则表达式中使用变量[2021-09-08]
你的正则这表达式有问题,试试这样: preg_match_all('/ -
使用正则表达式和PHP替换字符串中的最后一个数字(价格)?(Replace only last number (price) in a string using regex and PHP?)[2023-06-28]
我同意关于HTML解析器的stema,但是如果你真的想使用正则表达式,那么: $str = preg_replace('/(class="special-price">.*?)\d+,\d+/s', "$1 55,00", $str); I agree with stema about HTML parser, but if you really want to use regex, how about: $str = preg_replace('/(class="special-price">.*?)\ ... -
PHP中的正则表达式问题(Regex Problem in PHP)[2023-12-29]
如果你在正则表达式中使用'/',你可能不会用它开始/结束正则表达式。 例如,用'#'代替它。 if(!preg_match("#^(0[1-9]|[12][0-9]|3[01])[- /.](0[1-9]|1[012])[- /.](19|20)\d\d$#",trim($_POST['dob']))){ $error .= "You must enter a valid date of birth."; } (顺便说一下, 修饰符会在最后一个分隔符 '#'之后出现,所以警告就出现了,因为PHP认为正 ... -
使用正确的HTML解析器(如DOMDocument和preg_replace ( \s+ )) 仅删除“空格字符” (任何Unicode分隔符,制表符,换行符,回车符,垂直制表符,换页符) $dom = new DOMDocument(); $dom->loadHTML(file_get_contents("http://thesite.com"); $xpath = new DOMXpath($dom); foreach ($xpath->query("//p[@class='price-wrap']") ...
-
正则表达式模式必须以可选参数开始和结束。 此外,不要忘记逃离你模式中的所有特殊字符。 $pattern = '/
from ([0-9]+.*) EUR<\/strong><\/p>/'; 你可以使用Regexr之类的东西来测试你的模式。 我在这里为您创建了一个: http : //regexr.com/3f173 A regex pattern has to start and end with / followed by optional ...
-
在您自己的正则表达式中,您没有明确指定.php文件扩展名,因此引擎不知道哪些扩展名应该匹配,哪些不应该匹配。 你快要做了,只需要修改一下: ^(?:.(?!\.html))*\.php$ 现场演示 In your own regex you didn't explicitly specify .php file extension so engine doesn't have any idea which extensions should match and which shouldn't. You a ...
-
PHP - 帮助编写正则表达式?(PHP - Help writing regex?)[2022-04-07]
如果你想要“绝对任何东西”那么...不要添加任何其他东西! 您可以使用quanticator和其他类: $regex = '/color: #[a-fA-F0-9]{6};/' [a-fA-F0-9]匹配af(小写),AF(大写)和数字之间的任何字符。 {6}表示它必须有6个字符。 不要忘记,使用PHP的PCRE扩展,在这种情况下你需要分隔符(/)。 If you want "absolutely anything" then... don't add anything else! You can use ... -
这将是一个简单的例子: Preis: 1.199,00 Euro (inkl. 19% MwSt.)'; $pattern = '|]+class="price_label".*>[^<]+([0-9.,]+)\s*.*$|'; preg_match($pattern, $subject, $tokens); var_dump($toke ...
-
如果你知道你总是有一个小数: ^\d+\.\d{0,2} 这表示从字符串前面选择一个或多个数字,后跟一个小数,后跟最多2位数,它将忽略过去的任何内容。 If you know you'll always have a decimal: ^\d+\.\d{0,2} That says select one or more digits from the front of your string, followed by a decimal, followed by up to 2 digits and i ...
-
从索引1获取匹配的组。 (?<=>)(\d[^€]*) 演示 或者为每个数字获取匹配的组索引1和2 (?<=>)(\d+)\D(\d+)\D 演示 如果您只对标签感兴趣,请尝试以下正则表达式 ]*>(\d+)\D(\d+)\D[^<]* 演示 示例代码: import re p = re.compile(ur']*>(\d+)\D(\d+)\D[^<]*') test_str = u"..." re.findall(p, test_str) Get ...