内容的栏目 * @param int $category 0列表 1频道 2单页 3外链 * @return array */ function category_list($forumlist, $model = 0, $display = 0, $category = 0) { if (empty($forumlist)) return NULL; static $cache = array(); $key = $model . '-' . $display . '-' . $category; if (isset($cache[$key])) return $cache[$key]; if ($display) { foreach ($forumlist as $k => $val) { if (1 == $val['display'] && 1 == $val['type'] && $val['category'] == $category) { $cache[$key][$k] = $val; } } } else { foreach ($forumlist as $k => $val) { if (1 == $val['type'] && $val['category'] == $category) { $cache[$key][$k] = $val; } } } return empty($cache[$key]) ? NULL : $cache[$key]; } /** * @param $forumlist 所有版块列表 不分模型 * @param int $display 0全部CMS栏目 1在首页和频道显示内容的栏目 * @param int $category 0列表 1频道 2单页 3外链 * @return array */ function category_list_show($forumlist, $display = 0, $category = 0) { if (empty($forumlist)) return NULL; static $cache = array(); $key = $display . '-' . $category; if (isset($cache[$key])) return $cache[$key]; if ($display) { foreach ($forumlist as $k => $val) { if (1 == $val['display'] && 1 == $val['type'] && $val['category'] == $category) { $cache[$key][$k] = $val; } } } else { foreach ($forumlist as $k => $val) { if (1 == $val['type'] && $val['category'] == $category) { $cache[$key][$k] = $val; } } } return empty($cache[$key]) ? NULL : $cache[$key]; } /** * @param $forumlist 所有版块列表 * @return mixed BBS栏目数据(仅列表) 尚未开放bbs频道功能 */ function forum_list($forumlist) { if (empty($forumlist)) return array(); static $cache = array(); if (isset($cache['bbs_forum_list'])) return $cache['bbs_forum_list']; $cache['bbs_forum_list'] = array(); foreach ($forumlist as $_fid => $_forum) { if ($_forum['type']) continue; $cache['bbs_forum_list'][$_fid] = $_forum; } return $cache['bbs_forum_list']; } // 导航显示的版块 function nav_list($forumlist) { if (empty($forumlist)) return NULL; static $cache = array(); if (isset($cache['nav_list'])) return $cache['nav_list']; foreach ($forumlist as $fid => $forum) { if (0 == $forum['nav_display']) { unset($forumlist[$fid]); } } return $cache['nav_list'] = $forumlist; } ?>too many redirects error, mod_wsgi apache and django (python-venv) - Stack Overflow
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

too many redirects error, mod_wsgi apache and django (python-venv) - Stack Overflow

programmeradmin0浏览0评论

I have a problem, with django and apache (mod_wsgi), I get the browser error "too many redirects". Here my files and apache configuration

project tree

├── db.sqlite3
├── djangoProject
│   ├── asgi.py
│   ├── __init__.py
│   ├── __pycache__
│   ├── settings.py
│   ├── urls.py
│   └── wsgi.py
├── manage.py
└── sito
    ├── admin.py
    ├── apps.py
    ├── __init__.py
    ├── migrations
    ├── models.py
    ├── __pycache__
    ├── templates
    ├── tests.py
    ├── urls.py
    └── views.py

sito/urls.py

from django.urls import path

from . import views

urlpatterns = [
    path('', views.index, name='index'),
    path('display_config/', views.display_config, name='display_config'),
]

djangoProject/urls.py

from django.contrib import admin
from django.urls import path, include


urlpatterns = [
    path('admin/', admin.site.urls),
    path('', include('sito.urls')),
]

views.py

from django.http import HttpResponse
from django.shortcuts import render
from django.template import loader

from .models import PingAction, Config

from . import views 

def index(request):
    return HttpResponse("Hello, world.")

def display_config(request):
    config_list = Config.objects.all()
    template = loader.get_template("display_config.html")
    context = {
        "config_list": config_list,
    }
    return HttpResponse(template.render(context, request))

httpd.conf

WSGIScriptAlias /app-web /mnt/data/Workspace/app/app-web/djangoProject/djangoProject/wsgi.py
WSGIPythonHome /mnt/data/Workspace/app/app-web/app-web-env
WSGIPythonPath /mnt/data/Workspace/app/app-web/djangoProject


<Directory "/mnt/data/Workspace/app/app-web/djangoProject">
<Files wsgi.py>
   Require all granted
</Files>
</Directory>

When I navigate to http://localhost/app-web/sito/display_config the browser show me the "too many redirects" error. That in differents browsers.

If I use

python manage.py runserver 

and navigate to http://127.0.0.1:8000/ or http://127.0.0.1:8000/display_config all works correcty.

Can somebody help me please to understand what's wrong? Thank a lot

Update: I add an image of the developer tools bar when trying to load the page (from previous code I change app-web to melons-web, this is not the problem). I want also specify that this happen only on my linux machine, the same code in Windows works perfectly

I have a problem, with django and apache (mod_wsgi), I get the browser error "too many redirects". Here my files and apache configuration

project tree

├── db.sqlite3
├── djangoProject
│   ├── asgi.py
│   ├── __init__.py
│   ├── __pycache__
│   ├── settings.py
│   ├── urls.py
│   └── wsgi.py
├── manage.py
└── sito
    ├── admin.py
    ├── apps.py
    ├── __init__.py
    ├── migrations
    ├── models.py
    ├── __pycache__
    ├── templates
    ├── tests.py
    ├── urls.py
    └── views.py

sito/urls.py

from django.urls import path

from . import views

urlpatterns = [
    path('', views.index, name='index'),
    path('display_config/', views.display_config, name='display_config'),
]

djangoProject/urls.py

from django.contrib import admin
from django.urls import path, include


urlpatterns = [
    path('admin/', admin.site.urls),
    path('', include('sito.urls')),
]

views.py

from django.http import HttpResponse
from django.shortcuts import render
from django.template import loader

from .models import PingAction, Config

from . import views 

def index(request):
    return HttpResponse("Hello, world.")

def display_config(request):
    config_list = Config.objects.all()
    template = loader.get_template("display_config.html")
    context = {
        "config_list": config_list,
    }
    return HttpResponse(template.render(context, request))

httpd.conf

WSGIScriptAlias /app-web /mnt/data/Workspace/app/app-web/djangoProject/djangoProject/wsgi.py
WSGIPythonHome /mnt/data/Workspace/app/app-web/app-web-env
WSGIPythonPath /mnt/data/Workspace/app/app-web/djangoProject


<Directory "/mnt/data/Workspace/app/app-web/djangoProject">
<Files wsgi.py>
   Require all granted
</Files>
</Directory>

When I navigate to http://localhost/app-web/sito/display_config the browser show me the "too many redirects" error. That in differents browsers.

If I use

python manage.py runserver 

and navigate to http://127.0.0.1:8000/ or http://127.0.0.1:8000/display_config all works correcty.

Can somebody help me please to understand what's wrong? Thank a lot

Update: I add an image of the developer tools bar when trying to load the page (from previous code I change app-web to melons-web, this is not the problem). I want also specify that this happen only on my linux machine, the same code in Windows works perfectly

Share Improve this question edited Feb 4 at 16:27 luna80 asked Feb 2 at 5:59 luna80luna80 1533 silver badges16 bronze badges 16
  • Please share your project structure. I’m not sure how it would work correctly even with python manage.py runserver. Your urls.py look like they’re indeed the cause of the problem. – raphael Commented Feb 2 at 18:34
  • I edited my post with the tree of the project structure, and some others change, but the issue is still the same. thanks – luna80 Commented Feb 3 at 5:36
  • Sorry, I'm out of ideas. The changes you made to urls.py should have made the difference. All I can suggest is trying to restart the service, sudo systemctl restart httpd.service. – raphael Commented Feb 3 at 15:24
  • 1 @luna80, I tried running the project through Docker, with all your files and the Apache config you provided. And, expectedly, the problem did not reproduce, everything works. Do you have any customizations of your own in settings.py, if so, please attach them to the question. Have you tested incognito mode? Perhaps you have changed the Apache configuration before and have mod_rewrite enabled?, as again, with pure Apache, in docker the problem is not reproduced? Try as a last option to completely reinstall Apache. – Serhii Fomenko Commented Feb 6 at 13:12
  • 1 @SerhiiFomenko mod_rewrite was the problem!!! I don't know I have it enabled! I don't remeber I do this! Maybe a defalt value? I disable it and now all works perfectly! Thank you very much!! Can I ask you to put this solution as an answer so I can give you the bounty? – luna80 Commented Feb 8 at 6:03
 |  Show 11 more comments

2 Answers 2

Reset to default 1 +50

I assume that your problem is related to the Apache settings, on your linux machine, you probably have mod_rewrite enabled which is causing the redirection problem.

I think you have 2 URLs that come to (http://localhost/app-web/display_config) bt clearing this line in the main URL file the problem may be solved path('display_config/', include('sito.urls')),

发布评论

评论列表(0)

  1. 暂无评论