Django Apache重定向问题 [英] Django Apache Redirect Problem

查看:160
本文介绍了Django Apache重定向问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用mod_wsgi将我的Django项目配置为在Apache上运行。我试图在Apache上的目录'cflow'下运行Django,但是遇到重定向问题。



我的apache conf看起来像这样:

  ... 
WSGIScriptAlias / cflowC:\Program Files\Apache Software Foundation\Apache2.2\wsgi \django.wsgi
< DirectoryC:\Program Files\Apache Software Foundation\Apache2.2\wsgi>
订单允许,拒绝
允许从所有
< / Directory>
< DirectoryC:\Projects\myproject\src>
订单允许,拒绝
允许从所有
< / Directory>

我遇到的问题是,如果用户没有登录,请求/ cflow / somepage.html将被修改为/accounts/login?next=/cflow/somepage.html。这个新地址不在django根(cflow)下面,所以apache响应404找不到。



我的问题是如何将Django重定向映射为apache下的应用程序根目录下?即如何使/ accounts / ...页面改为/ cflow / accounts /...?



感谢任何帮助。

解决方案

事情要尝试:


  1. 更改当前域到网站框架中的yourdomain.tld / cflow。使用django admin或dumpdata / loaddata manage.py命令很容易。


  2. 看起来您的网站正在使用 login_required 装饰器。在这种情况下,您可以添加到 settings.py



    LOGIN_URL ='/ cflow / accounts / login /'



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.

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>

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.

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/...?

Thanks for any help.

解决方案

Things to try:

  1. 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.

  2. Looks like your site is using login_required decorator. In that particular case you can add to settings.py:

    LOGIN_URL = '/cflow/accounts/login/'

这篇关于Django Apache重定向问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆