0

It seems that changes to the urls.py file in my Django project are ignored unless I reload Apache. Any ideas why this is happening? This is my virutal host file:

<IfModule mod_ssl.c>
  <VirtualHost www.mydomain.com:443>
    ServerName www.mydomain.com
    ServerAdmin myaddress@mydomain.com

    WSGIScriptAlias / /var/www/html/www.mydomain.com/myproject/wsgi.py
    WSGIDaemonProcess myproject python-path=/var/www/html/www.mydomain.com:/var/www/html/www.mydomain.com/env/lib/python3.6/site-packages
    WSGIProcessGroup myproject

    <Directory /var/www/html/myproject>
       <Files wsgi.py>
          Order deny,allow
          Allow from all
       </Files>
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    # Let's Encrypt files
    SSLCertificateFile /etc/letsencrypt/live/www.mydomain.com/fullchain.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/www.mydomain.com/privkey.pem
    Include /etc/letsencrypt/options-ssl-apache.conf
  </VirtualHost>
</IfModule>

Changes are otherwise applied instantly, as I can check via the show_urls command from django-extensions.

1 Answers1

-1

Because python files are cached as byte code and uwsgi is using them.

Did you notice __pycache__ and *.pyc files are generated automatically whenever you run python files, those files are python byte code files.

You need set touch reload functionality in uwsgi configuration file to replace those cached files and generate fresh one in order to make changes to your latest edit.

In your uwsgi configuration file set it like below:

[uwsgi]

touch-reload = /path/to/your/django/project/reload.ini

If you do not have auto reload on uwsgi configuration files changes functionality, you need to reload app or restart uwsgi to take effect on new configuration.

Whenever you make changes to your code, you can reload using touch command.

$ touch /path/to/your/django/project/reload.ini

No need to reload or restart Apache.

Docs: The Art of Graceful Reloading

If your using git to push code, you can use post-receive hook to make this happen automatically.

Similar thread here How to configure Git post commit hook

Debendra
  • 1,132
  • 11
  • 22
  • The only thing I installed was `mod-wsgi` for Apache via the `libapache2-mod-wsgi-py3` package for Ubuntu. I'm not sure whether I've got `uwsgi` installed or how to change the config file for it. At least I am never actively calling uwsgi. How could I check that? Is it installed as part of Django? – PhilippVerpoort Feb 16 '19 at 16:25
  • which server you use? Django is just a python web framework,. uwsgi is server to run python programs. And django is using uwsgi. – Debendra Feb 16 '19 at 17:02
  • All I ever installed was Apache, the corresponding mod wsgi, and python+Django. So you are suggesting uwsgi was installed as part of that? Running `locate uwsgi` didn't yield anything. This is Ubuntu 18.04, Django 2.1.7, Python 3.6, Apache 2.4.29. – PhilippVerpoort Feb 16 '19 at 18:44
  • Neither did I find anything running `find . -name "*uwsgi*" -print` in the directory where my `virtualenv` is located. – PhilippVerpoort Feb 16 '19 at 18:47
  • use touch-reload on your apache configuration file as shown above. – Debendra Feb 16 '19 at 19:11
  • @Debendra you are incorrect and being confusing. Django does *not* depend on uwsgi, and OP is not using it. uwsgi is one possible WSGI server; but OP is using mod_wsgi. – Daniel Roseman Feb 16 '19 at 20:26