从相对路径为 Django 应用程序提供服务

发布于 2024-12-02 12:45:50 字数 796 浏览 0 评论 0原文

我正在开发一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

美胚控场 2024-12-09 12:45:50

调试信息位于:-/尝试在 URL conf 中使用更宽松的正则表达式;我能够得到一个页面。从那里我可以打印 request.path,结果是 app/myurl/

为了让它工作,我不得不把

FORCE_SCRIPT_NAME = ''
STATIC_URL = '/app/static/'
MEDIA_URL = '/app/media/'

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 be app/myurl/.

To make it work, I had instead to put

FORCE_SCRIPT_NAME = ''
STATIC_URL = '/app/static/'
MEDIA_URL = '/app/media/'
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文