Refresh urls.py cache in django - python

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.

Related

django - Changes in template files are not shown

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).

Django settings.py not updating on production

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.

Django: Push app from local server to production server via FTP

This is a bit embarassing, but I'm a Django noob and I couldn't find a simple solution to this:
I have written a Django app in a local VM that I now want to deploy to a "production" server. App works like a charm locally.
Now my IT colleague has set up the server with Django and that also works fine. I can open it via the Web and I get the usual "Congratulations on your first Django-powered page". I can also log into the admin interface. The project has been created.
This is a very low-key mini project and I'm not too familiar with git, so we've decided to just push files via FTP. (And I want to stick with that if at all possible.) So I uploaded the app folder into the project folder and also adjusted the project's settings.py and urls.py.
However, nothing seems to be happening on the server's end. The welcome page is the same, the app does not show up in the admin interface and the URLs won't be resolved as hoped.
Any suggestions what I should have done / done differently?
You need to restart apache or whatever is running your django project. Your changes to py files are cached when you first load your server config (settings).
Any suggestions what I should have done / done differently?
You should be using git/jenkins/deployment techniques, I know you said you've decided not to use it but you're going to be missing out on important things like being able to keep track of changes and unit testing

Django code changes not reflecting on production server

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

Restarting a Django application running on Apache + mod_python

I'm running a Django app on Apache + mod_python. When I make some changes to the code, sometimes they have effect immediately, other times they don't, until I restart Apache. However I don't really want to do that since it's a production server running other stuff too. Is there some other way to force that?
Just to make it clear, since I see some people get it wrong, I'm talking about a production environment. For development I'm using Django's development server, of course.
If possible, you should switch to mod_wsgi. This is now the recommended way to serve Django anyway, and is much more efficient in terms of memory and server resources.
In mod_wsgi, each site has a .wsgi file associated with it. To restart a site, just touch the relevant file, and only that code will be reloaded.
As others have suggested, use mod_wsgi instead. To get the ability for automatic reloading, through touching the WSGI script file, or through a monitor that looks for code changes, you must be using daemon mode on UNIX. A slight of hand can be used to achieve same on Windows when using embedded mode. All the details can be found in:
http://code.google.com/p/modwsgi/wiki/ReloadingSourceCode
You can reduce number of connections to 1 by setting "MaxRequestsPerChild 1" in your httpd.conf file. But do it only on test server, not production.
or
If you don't want to kill existing connections and still restart apache you can restart it "gracefully" by performing "apache2ctl gracefully" - all existing connections will be allowed to complete.
Use a test server included in Django. (like ./manage.py runserver 0.0.0.0:8080) It will do most things you would need during development. The only drawback is that it cannot handle simultaneous requests with multi-threading.
I've heard that there is a trick that setting Apache's max instances to 1 so that every code change is reflected immediately--but because you said you're running other services, so this may not be your case.

Categories

Resources