Apache2 not loading Django settings.py file properly
NickName:NithishB Ask DateTime:2022-12-22T22:38:34

Apache2 not loading Django settings.py file properly

I am currently facing an issue where making any changes in settings.py file is not reflecting properly in my project. I have tried deleting the .conf file, adding it again, enabling it and reloading the apache2 server. But somehow it still does not work.

I have an issue with CORS in Django, I made changes to correct it by allowing certain origins to make cross-origin requests:

CORS_ALLOWED_ORIGINS = ['www.test.domain',...]

So I tested it by running the Django server manually using python runserver 0.0.0.0:8000 and it is working fine, not getting any CORS issues

But when I reload the apache2 server or even in this case, make a completely new .conf file and run it via apache2 - it still somehow does not recognize the changes and keeps giving me CORS errors.

I am confused as to what is making this happen - to not reflect any newly made changes. The problem is, now I am not able to reflect these changes with a new configuration as well. So there is no way for me to keep this webserver running without getting CORS errors.

NOTE: Apache has all the required accesses to my Django project - it can access settings.py without any issues.

Tried: Disabling the backend.conf file, deleting it. Creating a new backend.conf file with the following config:

<Directory /home/django_project/main_django_project>
        <Files wsgi.py>
            Require all granted
        </Files>
    </Directory>
    
    WSGIScriptAlias / /home/django_project/main_django_project
    WSGIDaemonProcess app python-path=/home/django_project python-home=/home/venv
    WSGIProcessGroup app

Note: venv has all the required packages to run the django project

Also tried running the same Django project manually with python runserver 0.0.0.0:8000. Didn't see any CORS errors there, but immediately stopped this server and ran the apache2 server again and started seeing the CORS errors.

I also tried one more interesting thing: I set up a logger inside settings.py. It only wrote logs whenever I started the server manually using runserver command, it never wrote logs when it was being run in apache2 webserver which makes me think this settings.py is not being used at all somehow.

Copyright Notice:Content Author:「NithishB」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/74890018/apache2-not-loading-django-settings-py-file-properly

More about “Apache2 not loading Django settings.py file properly” related questions

Apache2 not loading Django settings.py file properly

I am currently facing an issue where making any changes in settings.py file is not reflecting properly in my project. I have tried deleting the .conf file, adding it again, enabling it and reloadin...

Show Detail

how to run Django application in apache2

Hi All i am not able to run a django application in apache2 webserver. I have went through all the document but it still did not work for me.This is my Apache2's httpd.conf file &lt;Location "/mys...

Show Detail

apache2 with django - can't write to log file

I have django running on apache2 server. my settings.py looks like this: WSGI_APPLICATION = 'my_app.wsgi.application' ... LOGGING = { 'version': 1, 'disable_existing_loggers': False,

Show Detail

What should the Django DATABASE settings be in settings.py when you are using Apache2, Python, and Django on Ubuntu 12.04 and MSSQL on another server?

What should the Django DATABASE settings be in settings.py when you are using Apache2, Python, and Django on Ubuntu 12.04 accessing an MS SQL database on another server? Currently my settings are:

Show Detail

Django Apache2 Logging and REST Problems

I have deployed a Django app using Apache2 and it works fine. However when I add either REST framework or logging the app doesn't respond properly. To note is that all works fine using 'manage.py

Show Detail

How to properly format django settings.py?

I'm a django beginner and am reading "Practical django Projects". The book instructs to insert the following- DATABASE_ENGINE = ‘sqlite3′ However, in the settings.py file DATABASES is instead a

Show Detail

How to create a settings.py file for an existing django project

It seems to be a Django best practice to add the settings.py file to the ignore list of the version control system. But how does one start to set up a project when the settings.py file was not incl...

Show Detail

a way to have django SITEURL constant in settings.py

I am from PHP background, and I know that constants can be accessed at most of places in a framework and I think it is same in django as well. I tried to have that URL too in django but I tried to ...

Show Detail

Django settings.py not being detected

I'm pretty new to Django and I'm having some difficulty getting my settings.py to load properly. I'm getting the following error: ImproperlyConfigured at /admin Put 'django.contrib.admin' i...

Show Detail

Permission denied when uploading file (Django, Apache2)

I deployed a beta version of my django app to DigitalOcean and I am serving it using Apache2 for both python and static files. Here is the issue, when I upload a file, it gives me the following er...

Show Detail