Score:2

Urls.py not updating on Django production server , which uses nginx and gunicorn

in flag

I am currently hosting a Django Webapp on an AWS EC2 instance, To run it in production mode I use NGINX and gunicorn.

The Error that I am facing is:

The production server doesnt seem to update urls.py, no matter what I do

App used to transfer files from local file to instance : FileZilla

Steps that I have taken trying to solve the issue:

  1. Deleting the urls.py and rewriting it

  2. Checking if other files also refuse to get updated

    RESULT of 2nd step: Other files are successfully getting updated, I tested with static files and with index.html

  3. Checking if the file is updated in the instance using The nano editor

    RESULT of 3rd step: The file is properly updated in the instance, with all changes being reflected

  4. Running it on the instance using python manage.py runserver (for development purposes), and found out that the urls.py is getting updated properly when using runserver

Other Information:

1.Everything was getting updated properly just yesterday, but suddenly it decides to act rebellious

  1. I have updated all packages using sudo yum install

  2. I have restarted nginx and gunicorn: using commands such as :

    sudo systemctl start gunicorn

    sudo systemctl enable gunicorn

    sudo systemctl restart nginx

  3. I have tried checking for errors using sudo nginx -t, but no errors show up

  4. I've checked the error logs, using sudo tail -f /var/log/nginx/error.log , but no errors show
    up here either

How do I solve this?

Thank you

Michael Hampton avatar
cz flag
Your application is dynamically rewriting urls.py? Check wherever it is [logging](https://docs.djangoproject.com/en/3.2/topics/logging/) for any relevant messages.
Madhav avatar
in flag
Im sorry, but this is the first time im hearing about logging , so it might take me sometime to figure out how to 'log' , so my next response might take some time and thank you for helping me anyways
Madhav avatar
in flag
And regarding the dynamically rewriting urls.py.. in the production server yes, it isnt getting updated, rather than rewriting .... but when I host it using manage.py runserver , it seems to work just fine, and the same files are used in both production and development
Michael Hampton avatar
cz flag
You can click the link to find out about logging. The defaults are shown at the end of the page. If you didn't configure logging then they'll be sent to stdout or stderr and end up in the systemd journal (unless you configured the systemd service unit to redirect those).
Madhav avatar
in flag
@MichaelHampton Ive also noticed that view.py didnt update, and that the only thing that updates properly is html files and static files, Im working on the logs right now. but thought, I should let you know this observation, incase this cld tell you more abt my issue
Madhav avatar
in flag
MIchealllll I solved it ...... it turns out that I needed to restart my gunicorn using `sudo systemctl restart gunicorn`, thank you so much for trying to help me , especially introducing me to logs, ill look into those
anx avatar
fr flag
anx
Bonus points for writing a question actually quoting the key problem.. ***restarting** [..] gunicorn using [..] **start** [instead of restart]* ;)
Madhav avatar
in flag
appreciate the upvote!!
Score:1
in flag

Ok so I found the solution.

Steps taken to solve it:

  1. I tried to use python3 manage.py runserver on my instance, and found out that the files were updated fine , therefore the issue was with the production side

  2. I figured out that only static and html files were being updated (nginx serves those) , so the problem was not with that

  3. I was using gunicorn to help with the views.py and urls.py and other such files, so the problem could be with gunicorn

FINAL SOLUTION:

So I ran the command sudo systemctl restart gunicorn, and the code worked perfectly

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.