Django Apache 重定向问题
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1036186/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Django Apache Redirect Problem
提问by liminal
I'm configuring my Django project to run on Apache using mod_wsgi. I am attempting to run Django below the directory 'cflow' on apache, but am running into problem with redirects.
我正在使用 mod_wsgi 配置我的 Django 项目以在 Apache 上运行。我试图在 apache 上的“cflow”目录下运行 Django,但遇到重定向问题。
My apache conf looks something like this:
我的 apache conf 看起来像这样:
...
WSGIScriptAlias /cflow "C:\Program Files\Apache Software Foundation\Apache2.2\wsgi\django.wsgi"
<Directory "C:\Program Files\Apache Software Foundation\Apache2.2\wsgi">
Order allow,deny
Allow from all
</Directory>
<Directory "C:\Projects\myproject\src">
Order allow,deny
Allow from all
</Directory>
The problem I'm running into is that if the user is not logged in, a request for /cflow/somepage.html will be reidrected to /accounts/login?next=/cflow/somepage.html. This new address is not below the django root (cflow), so apache responds with a 404 Not Found.
我遇到的问题是,如果用户没有登录,对 /cflow/somepage.html 的请求将被重定向到 /accounts/login?next=/cflow/somepage.html。这个新地址不在 django root (cflow) 之下,所以 apache 以 404 Not Found 响应。
My question is how can I have the Django redirects mapped to be below the applications root directory on apache? I.e. how can I make the /accounts/... page be instead /cflow/accounts/...?
我的问题是如何将 Django 重定向映射到 apache 上的应用程序根目录下?即如何使 /accounts/... 页面改为 /cflow/accounts/...?
Thanks for any help.
谢谢你的帮助。
回答by alex vasi
Things to try:
尝试的事情:
Change current domain to "yourdomain.tld/cflow" in the "sites" framework. It's easy to do using django admin or dumpdata/loaddata manage.py commands.
Looks like your site is using login_requireddecorator. In that particular case you can add to settings.py:
LOGIN_URL = '/cflow/accounts/login/'
在“站点”框架中将当前域更改为“yourdomain.tld/cflow” 。使用 django admin 或 dumpdata/loaddata manage.py 命令很容易做到。
看起来您的网站正在使用login_required装饰器。在这种特殊情况下,您可以添加到settings.py:
LOGIN_URL = '/cflow/accounts/login/'

