Free Hosting a Python API. Hosting a Python Django Backend REST… - by Trần Hoàng Long - Medium
Free Hosting a Python API. Hosting a Python Django Backend REST… - by Trần Hoàng Long - Medium
Get unlimited access to the best of Medium for less than $1/week. Become a member
62 1
Foreword
https://medium.com/@produde/free-hosting-a-python-api-632968f14b20 1/17
12/29/23, 2:36 AM Free Hosting a Python API. Hosting a Python Django Backend REST… | by Trần Hoàng Long | Medium
If you had some of the similar problems, this blog could be for you. I’ll
discuss some of my findings and workarounds below
https://medium.com/@produde/free-hosting-a-python-api-632968f14b20 2/17
12/29/23, 2:36 AM Free Hosting a Python API. Hosting a Python Django Backend REST… | by Trần Hoàng Long | Medium
TOC
· Foreword
· TOC
· Project Description
∘ Database
∘ Backend
∘ Frontend
· Hosting Service
· Render Hosting
∘ Build server
∘ Environment Variables
∘ Run server
· Demo
· Final words
Project Description
So here’s a quick layout of my project at the time, called Geo-covid , which is
basically a visualization website for the covid problem in USA, which
consists of 3 parts
Database
https://medium.com/@produde/free-hosting-a-python-api-632968f14b20 3/17
12/29/23, 2:36 AM Free Hosting a Python API. Hosting a Python Django Backend REST… | by Trần Hoàng Long | Medium
‼️ This (db connection from/to the backend) proven itself to be the trickiest
part of the server hosting process
Backend
My API implemented with Python and Django REST API
Why Django REST and not Fast API? Well cause I just wanna try Django out
for once.
Frontend
Web visualization with the help of Tailwind CSS and D3.js (graph) and
Leaflet (map)
We don’t focus on the frontend here since free hosting for frontend JS is
everywhere and it only make simple request back/forth to our API server.
Hosting Service
https://medium.com/@produde/free-hosting-a-python-api-632968f14b20 4/17
12/29/23, 2:36 AM Free Hosting a Python API. Hosting a Python Django Backend REST… | by Trần Hoàng Long | Medium
After some trial and error, the two contenders that were the most promising
were:
1. render.com
2. pythonanywhere.com
But in the end, pythonanywhere fell short of my need, despite being the more
comprehensive and dev friendly service. All because of the previously
mention DB connection problem 😮💨
You see on the free tier, pythonanywhere only allow external connection
under the https protocol, so my Mongo Atlas connection is of mongodb://
Render Hosting
The hosting procedure is very detaily describe on Render 's documentation
(Django Quickstart Doc). So I’m just going to point out notable things from
my project
https://medium.com/@produde/free-hosting-a-python-api-632968f14b20 5/17
12/29/23, 2:36 AM Free Hosting a Python API. Hosting a Python Django Backend REST… | by Trần Hoàng Long | Medium
3. Run server
Build server
Python env
All we need here is a requirement.txt file that we’lll use to install packages
when building our source code with pip install -r requirement.txt
Static files
Static files for Django server API GUI could be generated with python
manage.py collectstatic
https://medium.com/@produde/free-hosting-a-python-api-632968f14b20 6/17
12/29/23, 2:36 AM Free Hosting a Python API. Hosting a Python Django Backend REST… | by Trần Hoàng Long | Medium
Build
We put all the needed commands for server preping in the Build Command
option for Render (found in Settings > Build & Deploy > Build Command ). I set
it as
Environment Variables
Found in Environment tab
This includes:
https://medium.com/@produde/free-hosting-a-python-api-632968f14b20 7/17
12/29/23, 2:36 AM Free Hosting a Python API. Hosting a Python Django Backend REST… | by Trần Hoàng Long | Medium
DEBUG=FALSE
DB_URL="mongodb+srv://<username>:<password>@<cluster_address>.mongodb.net/?retry
DEPLOY_ENV=production
❓For anyone wondering how in the code I connected to Atlas , here’s that
snippet
https://medium.com/@produde/free-hosting-a-python-api-632968f14b20 8/17
12/29/23, 2:36 AM Free Hosting a Python API. Hosting a Python Django Backend REST… | by Trần Hoàng Long | Medium
Run server
Search Settings > Build & Deploy > Run Command Write
Key takeaway is that I ran it with gunicorn and some extra port, worker
settings.
After all the settings, just run deploy with latest commit 🤲
Demo
https://medium.com/@produde/free-hosting-a-python-api-632968f14b20 9/17
12/29/23, 2:36 AM Free Hosting a Python API. Hosting a Python Django Backend REST… | by Trần Hoàng Long | Medium
After getting the DB up and then the backend API online, I try making
connections to it from my frontend and everything is nice/clean 👩🍳🥳
The server might not be online anymore but as of now, my frontend is still
online and you can visit it at https://geo-covid-frontend.web.app/
Demo
Final words
https://medium.com/@produde/free-hosting-a-python-api-632968f14b20 10/17
12/29/23, 2:36 AM Free Hosting a Python API. Hosting a Python Django Backend REST… | by Trần Hoàng Long | Medium
Those are my findings while tring to get my side project online. It’s quite
messy and erroneous overall but I’m quite happy that it’s online.
But please, do comment your thought on my topic and clap if it helped in any
ways. Would love to hear from you ⭐
https://medium.com/@produde/free-hosting-a-python-api-632968f14b20 11/17
12/29/23, 2:36 AM Free Hosting a Python API. Hosting a Python Django Backend REST… | by Trần Hoàng Long | Medium
69 Followers
246 9 1
https://medium.com/@produde/free-hosting-a-python-api-632968f14b20 12/17
12/29/23, 2:36 AM Free Hosting a Python API. Hosting a Python Django Backend REST… | by Trần Hoàng Long | Medium
15 15
https://medium.com/@produde/free-hosting-a-python-api-632968f14b20 13/17
12/29/23, 2:36 AM Free Hosting a Python API. Hosting a Python Django Backend REST… | by Trần Hoàng Long | Medium
74 1 137 1
Lists
https://medium.com/@produde/free-hosting-a-python-api-632968f14b20 14/17
12/29/23, 2:36 AM Free Hosting a Python API. Hosting a Python Django Backend REST… | by Trần Hoàng Long | Medium
52 1 205
https://medium.com/@produde/free-hosting-a-python-api-632968f14b20 15/17
12/29/23, 2:36 AM Free Hosting a Python API. Hosting a Python Django Backend REST… | by Trần Hoàng Long | Medium
Sandyjtech Dhwajgupta
15 7 2
https://medium.com/@produde/free-hosting-a-python-api-632968f14b20 16/17
12/29/23, 2:36 AM Free Hosting a Python API. Hosting a Python Django Backend REST… | by Trần Hoàng Long | Medium
Help Status About Careers Blog Privacy Terms Text to speech Teams
https://medium.com/@produde/free-hosting-a-python-api-632968f14b20 17/17