luna80
luna80

Reputation: 153

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

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

developer tools screenshot

Upvotes: 0

Views: 208

Answers (2)

Serhii Fomenko
Serhii Fomenko

Reputation: 1030

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.

Upvotes: 1

mohammadreza
mohammadreza

Reputation: 7

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')),

Upvotes: 0

Related Questions