2024-06-16 09:16:44 发布
网友
如何比较referer URL和reverse()URL?在
reverse()
以下是我当前的代码:
if request.META.get('HTTP_REFERER') == reverse('dashboard'): print 'Yeah!'
但这不起作用,因为反向操作将输出/dashboard,而HTTP_REFERER输出{}
/dashboard
HTTP_REFERER
我目前的解决方案是:
我不知道这是不是最好的办法。任何建议都很好。在
您可以使用urlparse从URL获取path元素。在Python3中:
urlparse
from urllib import parse path = parse.urlparse('http://localhost:8000/dashboard/').path
在python2中:
您可以使用
urlparse
从URL获取path元素。在Python3中:在python2中:
^{pr2}$相关问题 更多 >
编程相关推荐