I made so changes in one of my model-forms in my Django apps - I added new input fields for the user. I then tested the changes in my environment and everything works fine. I then committed and pushed the changes to remote repo. I pulled the changes on my production server which runs on AWS. I ran pkill -f runserver in terminal to restart the server, however the changes didn't take place. Only the changes regarding html tags were visible (new labels and etc...).
The changes that weren't present are the ones that come from the model-from: new input fields for the user - those were just missing completely from the template page.
What can be causing this behaviour?
you need to restart gunicorn service every time you make changes to the code.
run sudo systemctl restart gunicorn
Do it and changes will reflect.
After you push changes to the production server you also need to migrate the database changes.
On your local repo (where you make your model changes) you run the makemigrations command
python manage.py makemigrations
And after you fetch your changes on your production server you run the migrate command
python manage.py migrate
It depends on the server you're using : nginx, gunicorn, or apache..
If you setup the server using nginx and gunicorn , you could probably try restarting those services manually, but i'd recommend using something like supervisord to ease out the restart procedure..
If ur using apache, probably use
sudo service httpd restart
If you use supervisor then you need to run
sudo supervisorctl reload
I was having the same problem, this command worked for me on AWS - Ubuntu Server 18.04 LTS.
Related
I deployed my Django application to the internet and every time after changing codes, I have to run this command to make changes happen:
sudo systemctl restart gunicorn
Is there any way to run this command through codes (for example in views)? or schedule it?
Or is there any way to force Gunicorn restarts after changing in codes?
I have tried Subprocess but I couldn't make it work.
You could use fabric script to restart gunicorn.
Check this link Automate Deployment With Fabric Python
I have a Django app that I am trying to deploy to AWS.
I need two command lines to run the app. One command line will be used to runserver and another one to run a background task. That is how the app runs in my localserver.
How do I start two command lines in AWS?
As i can understand your django app is currently in development mode, I've used tmux for development mode, this page will guide you better to use tmux. Once you have started a tmux session run python3 manage.py runserver and then detach to the session using ctrl-b then press d and now your app will run even after you exit the shell.
To know more about tmux go through this page.
In case you have to run your app in production mode Don't use above method, run your app with any of nginx or apache2 server. This tutorial can guide you to set up your django app with nginx and gunicorn.
Supervisor is a good way to control that. You can run a lot of processes (like server, migration, collectstatic, Celery) easily.
Additionally, you can ensure that all processes will run again when your machine reboots.
And, as everybody said, you have to install a server in production that supports WSGI in order to run Django properly.
I am relatively new to Python/Django and have successfully deployed my first app. I want to update it now with some new changes, but I am not sure what the proper process is. My setup is ubuntu/nginx/gunicorn/postgres.
At the moment I am taking the following steps:
Stop nginx: sudo service nginx stop
Stop gunicorn: sudo service gunicorn stop
Backup the db? (not implemented - cant find it on the server)
Git Pull
python manage.py migrate
python manage.py collectstatic
restart gunicorn: sudo service gunicorn start
restart nginx: sudo service nginx restart
This is working, but I would appreciate some guidance if this is the complete, most accurate and safest way to do this please?
One lazy (yet recommended and professional) way of going about app updates is running automation script, like Fabric or Ansible.
However, if you wish to proceed the manual way (which is tedious), you might do something like:
Pull from git
Run migrations python manage.py migrate (This should ensure changes you made locally to your models reflect in production DB)
Run static collections to ensure new statics are reflected in server /static/ folder like so: python manage.py collectstatic
Then, restart your Django Server not Nginx. So something like: sudo service your_django_server_running_instance restart
On digitalOcean for instance (when used One-Click Install), your django server running instance is likely called gunicorn
Then you might want to look into automating your postgresql db as well
I'm working on developing a web app using Django, hosted on Gunicorn and Nginx. It's getting a bit inconvenient to run "sudo service nginx restart; sudo service gunicorn restart" every time I make a change to the code. Is there a way I can make them restart automatically whenever I make a change, or make it so the changes show up without having to restart?
You could add the '--reload' argument, as mentioned in the gunicorn documentation.
Restart workers when code changes.
This setting is intended for development. It will cause workers to be
restarted whenever application code changes.
Source: http://docs.gunicorn.org/en/latest/settings.html
I run ssh ubuntu#myapp.com, change to the django directory for my app and then run ps | aux less. I do not see any processes with python in the command. How do I restart my django server as it is running in the background?
It depends how you're running the Django server. If you set the Django server to run with Apache, sudo service apache2 restart will do the trick.
If you're running the test server (manage.py runserver), you could use fg to bring the job into the foreground, and tinker with it, but the Django development server automatically detects changes for you (there's no need to restart).