Lessons From Launching This Site
2022-12-17
What should have been a process of an hour or two turned into over two weeks of banging my head against the wall of the Django/Gunicorn/Nginx stack. It was frustrating while I was in it, but now that I’m on the other side of it, I wouldn’t trade the experience or time for an easier one.
Here are a few of the highlights:
Lesson 0: Grit > Talent
When I started my journey to become a Python/Web Developer with CodingNomads, the first course I went through was about learning how to learn. My big takeaway from that course was from this video. Grit is more important than natural talent in determining success. To keep it top of mind, I reduced it to ‘grit > talent’ and wrote it in multiple places where I could see it often as a reminder. And boy did I need those reminders when I started working on website deployment. By sticking to it, getting a lot of good help from my mentor, and scouring the internet for answers, I eventually succeeded.
Lesson 1: Environment Matters
This was the problem that stumped me for the longest time. Like all good problems, once I found the solution it seemed so obvious. Basically, I had the Secret Key for my Django app inside of the venv’s (virtual environment) activate
file. In my previous Python apps this has not been an issue. I activate the venv when I need to run the app and deactivate it when I’m done. However in deployment of a Django app, the venv doesn’t stay activated so Gunicorn could not find the Secret Key when trying to serve the app. Moving the environment variables outside of the venv into a .env
file within the apps main directory allowed Gunicorn to see the variables. Problem solved! (Here is a more in depth write-up of this issue I posted to Stackoverflow.)
Lesson 2: Get Permission
Once Gunicorn was happy, I was happy to see my website being displayed out here on the internet. However, it didn’t look right. My static files were still not being displayed. They were in the right spot, Nginx was configured correctly, and yet my site had the styling of, well, HTML. This time the answer did not take so long to find. Again, with the help of my mentor, I eventually discovered that the directory containing my static files did not have the appropriate permissions applied. As soon as I gave the static file the appropriate permissions (sudo chmod -R 775 static *
) this website finally displayed as you see it now.
Go Back