从相对路径为 Django 应用程序提供服务
我正在开发一个 Django 应用程序,它在本地运行良好。在生产中,应用程序将从相对路径提供服务,例如 www.example.com/app/
。
我将 Apache 与 mod_wsgi 结合使用,并且已将 Apache 配置为从相对 URL 为应用程序提供服务:
WSGIScriptAlias /app /path/to/my/modwsgi.py
WSGIDaemonProcess app display-name=app_wsgi
不幸的是,我收到错误 404。不过,调试信息非常神秘。如果我尝试获取 www.example.com/app/myurl/
,Django 会说
Using the URLconf defined in apps.urls, Django tried these URL patterns, in this order:
^myurl/$
...
The current URL, myurl/, didn't match any of these.
Django 似乎正确地推断出请求的路径是 myurl/
,而不是app/myurl/
。但是,即使 myurl/
明显匹配 ^myurl/$
,它也找不到匹配项。
我也尝试添加设置
FORCE_SCRIPT_NAME = '/app'
,但没有任何变化 - 错误消息保持不变。
I am developing a Django application which works fine locally. In production, the application will be served from a relative path, such as www.example.com/app/
.
I am using Apache with mod_wsgi, and I have configured Apache to serve the application from the relative URL:
WSGIScriptAlias /app /path/to/my/modwsgi.py
WSGIDaemonProcess app display-name=app_wsgi
Unfortunately, I get an Error 404. The debug information, though, is pretty mysterious. If I try to get www.example.com/app/myurl/
, Django says
Using the URLconf defined in apps.urls, Django tried these URL patterns, in this order:
^myurl/$
...
The current URL, myurl/, didn't match any of these.
It seems that Django - correctly - infers that the path requested is myurl/
, and not app/myurl/
. But, even though myurl/
clearly matches ^myurl/$
, it does not find a match.
I have also tried to add the setting
FORCE_SCRIPT_NAME = '/app'
but nothing changes - the error message remains identical.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
调试信息位于:-/尝试在 URL conf 中使用更宽松的正则表达式;我能够得到一个页面。从那里我可以打印
request.path
,结果是app/myurl/
。为了让它工作,我不得不把
The debug information lies :-/ Trying with more permissive regexs in the URL conf; iwas able to get a page. From there I could print
request.path
, and it turned out to beapp/myurl/
.To make it work, I had instead to put