Django Apache 重定向问题 [英] Django Apache Redirect Problem
问题描述
我正在使用 mod_wsgi 配置我的 Django 项目以在 Apache 上运行.我试图在 apache 上的cflow"目录下运行 Django,但遇到重定向问题.
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.
我的 apache conf 看起来像这样:
My apache conf looks something like this:
...
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>
我遇到的问题是,如果用户没有登录,对/cflow/somepage.html 的请求将被重定向到/accounts/login?next=/cflow/somepage.html.这个新地址不在 django root (cflow) 之下,所以 apache 以 404 Not Found 响应.
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.
我的问题是如何将 Django 重定向映射到 apache 上的应用程序根目录下?IE.我怎样才能让/accounts/... 页面改为/cflow/accounts/...?
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 admin 或 dumpdata/loaddata manage.py 命令很容易做到.
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.
看起来您的网站正在使用 login_required 装饰器.在这种特殊情况下,您可以添加到 settings.py:
Looks like your site is using login_required decorator. In that particular case you can add to settings.py:
LOGIN_URL = '/cflow/accounts/login/'
LOGIN_URL = '/cflow/accounts/login/'
这篇关于Django Apache 重定向问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!