简体   繁体   English

如何在Django的urls.py中匹配此URL?

[英]How do I match this URL in Django's urls.py?

I want to match a url that: 我想匹配一个URL:

begins with /signup /signup开头

and ends with password=goodbye 并以password=goodbye结束

That's it. 而已。 If something begins with that and ends with that, how do I match that in regex? 如果某些事情以此开头和结尾,我该如何在正则表达式中进行匹配?

I understand that I should do this in urls.py, but I have to because of certain reasons. 我知道我应该在urls.py中执行此操作,但是由于某些原因,我必须这样做。

Please answer how I would match it this way. 请回答我将如何以这种方式进行匹配。 I have to because a iPhone client (which cannot be changed) hardcoded it this way. 我必须这样做,因为iPhone客户端(无法更改)以这种方式进行了硬编码。 I know it's not ideal, but I have to match it this way now. 我知道这并不理想,但是我现在必须以这种方式进行匹配。

Don't ever send passwords in the URL. 永远不要在URL中发送密码。 They belong in the POST body, which is not stored by browsers (you can repeat POSTs in browsers, but POST data is not stored in the history). 它们属于POST主体,该主体不由浏览器存储(您可以在浏览器中重复POST,但是POST数据不存储在历史记录中)。

(r'^/signup/(.*)password=goodbye$', ...

You should just match for /signup . 您应该只匹配/signup You can get the password through the request object: 您可以通过请求对象获取密码:

//Your url handler:
def signup_handler(request):
    password = request.GET["password"]
    ...

But you shouldn't be passing the password as a GET argument... 但是您不应该将密码作为GET参数传递...

you can have something like this in your urls.py : 您可以在urls.py中添加以下内容:

(r'^/signup/password=(?P<password>.*)/$, signup_action)

and in your views.py you have : 在您的views.py中,您有:

def signup( request, password ):
     .....

PS : it not a good idea to pass password in url PS:在URL中传递密码不是一个好主意

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM