首页 > 解决方案 > 使用 django 和 nginx 解析 URL

问题描述

所以我正在构建一个 django web 应用程序并尝试使用 nginx 部署它。

langing 页面加载,但是当我单击链接时,我收到 nginx 400 Bad Request 错误。

浏览器中的 url 将如下所示:

"GET /%7B$%%20url%20'members:member_login'%20%%7D HTTP/1.1" 400 173 "-" "-" "-"

但是,如果我进入浏览器并手动删除多余的字符以获得:

/url'members:member_login'

然后它可以正常工作并呈现页面。有谁知道我可以在我的 nginx 配置文件或 django 代码中添加什么来解决这个问题?它已经难倒了我 2 周。

标签: pythondjangourlnginxencoding

解决方案


This looks like an error in your template: %7b is {, %20 is . I think you might have a typo in the href attribute of the link you clicked, could it be:

<a href="{$% url 'members:member_login' %}">...

instead of

<a href="{% url 'members:member_login' %}">...

With these kinds of errors, always make sure to inspect the actual html source in your browser (right click -> 'View page source' in chrome).


推荐阅读