I have a server that is live right now, there is some SMTP stuff I want to change the settings.py of my Django project. I have made the changes, however, I cannot get the server to detect the changes, and it throws a SMTPAuthentication error because the settings.py is still using the old settings.
The server is set up with nginx, and I have tried service nginx reload several times, and apachectl restart several times. As well as deleting any *.pyc files.
nginx cannot be actually running the site, as it is not a WSGI server. Presumably it is running as a proxy to something like gunicorn or uWSGI; it is those that you need to restart.
Autoreload in production is not good idea, but if you understand what you do, you can use additional python module for autoreloading or use additional param for uwsgi. Django devel autoreloading not works with uwsgi.
Related
I'm working on a django project, after changing some templates, it works on my local machine, but after uploading to production server (+restarting Apache) webserver shows the old code!
Its about few specific base template files.
I have tried to restart server, reload webserver and reinstall venv.
None of it worked.
Do I use template/fragment caching? No.
Do I use apache's caching? No.
UPDATE :
i just made some changes to one of another app's template files and uploaded it
after refresh, it updated right away!
now i am pretty sure that this problem is happening to only 1 of my apps
In my case, using gunicorn, I solved it this way:
sudo systemctl restart gunicorn-django-tutorial.service
The changes are not shown in production because gunicorn needs to reload the configuration.
A restart of the web server is not needed (I'm using Nginx).
Anything I modify on my Django app has no effect with what's live on the webapp itself. I can delete the entire project directory and my Django app still works.
With Django and Apache, I would simply enter:
/etc/init.d/apache2 restart
And any changes made to my Django application would go live immediately after Apache was restarted. But with this new Nginx, the same thing doesn't work:
/etc/init.d/nginx restart
My Django home page still shows the:
It worked!
Congratulations on your first Django-powered page.
How do I make my Python changes go live with Django and nginx?
What is your Nginx configuration? What is your WSGI runner, are you using Nginx-wsgi or the inbuilt Django 'runserver' command?
It sounds like the "it worked" page is on a separate port, and you're testing it directly -- not via Nginx. It's really easy to get the two of them confused :)
Nvm just figured it out. For Django One Click Install Image on Digital Ocean you need to run:
service gunicorn restart
After you've made all the changes and you'd like to test changes to your web app.
I changed a .py file and changes reflected on local dev. server for Django after deleting .pyc.
The production server does not even have .pyc for this specific file. Tried touching apache wsgi and restarting apache on prod. server but no luck.
Even deleting this .py file makes application work the same. There is memcached installed but I don't have much idea how it caches, there is .git as well and 5 servers are hosting - one main, 4 load balancers.
Regards !
Are 100% sure you are looking at the right server you are making the changes to? I know that sounds stupid but, why don't you stop Apache, can you still run the page then? IF you can then you definitely don't have the correct server.
If not, next try reloading Apache (thats different from restarting).
sudo service apache2 reload
If this still does not work then post your Apache setup, if must be looking on the wrong folder to the one your pushing to.
You have to restart your server (WSGI, UWSGI or whatever your use on production environment)
If you use uwsgi as gateway set touch-reload param in uwsgi settings
and you need just
$ touch <your-touch-reload-file>
in console for reflecting on changes
If you use apache with mod_python or mod_wsgi, you have to restart apache for apply changes
I'm using django on nginx with FastCGI and i have a problem with urls.py. According to this question, django caches url.py file and i'm - just like above question's author - not able to modify my URLs definitions.
My question is - is there any way to clear url cache in django/nginx/fcgi without server restart (which not helps anyway)?
This is not just a urls.py thing, it's normal workflow for running a wsgi or fastcgi app. The module is in memory, and it doesn't get reloaded from disk until you tell the server that it's changed.
As per Django's FastCGI docs:
If you change any Python code on your site, you'll need to tell FastCGI the code has changed. But there's no need to restart Apache in this case. Rather, just reupload mysite.fcgi, or edit the file, so that the timestamp on the file will change. When Apache sees the file has been updated, it will restart your Django application for you.
If you have access to a command shell on a Unix system, you can accomplish this easily by using the touch command:
touch mysite.fcgi
For development, in most cases you can use the django development server, which watches for code changes and restarts when it sees something change.
You don't need to restart the whole server, just your FastCGI app. However, I don't know why you say this doesn't help - this is the way to do it. It can't not help.
I configured my development server this way:
Ubuntu, Apache, mod_wsgi, Python 2.6
I work on the server from another computer connected to it.
Most of the times the changes don't affect the application unless I restart Apache.
In some cases the changes take effect without restarting the webserver, but after let's say 3 or 4 page loads the application might behave like it used to behave previous to the changes.
Until now I just reloaded everytime apache as I have the development server here with me, but HELL after a while got so annoying. How can I avoid this?
I can't work with the development server as I need an environment that is as close as possible as the production one.
Thanks
My suggestion is that you run the application in daemon mode.
This way you won't be required to restart apache,
just touch my_handler.wsgi and the daemon will know to restart the app. The apache httpd will not be only yours (in production) so it is fair not to restart it on every update.
No changes require you to RESTART. You simply need to reload using "sudo /etc/init.d/apache2 reload". Which I have aliased in my bashrc to 'a2reload'.
function a2reload (){
sudo /etc/init.d/apache2 reload
}
Apache loads Django environment when starting and keep running it even when source is changed.
I suggest you to use Django 'runserver' (which automatically restarts on changes) in heavy development sessions, unless you need some Apache-specific features (such as multi-thread).
Note also that changes in templates do not require the restart of the web server.