Sometimes when developing our Django application, we need to make it publicly accessible or want to share it with a friend without deploying it live.
To achieve it We can use ngrok to redirect what you are running on localhost to publicly available ngrok URL. Let’s get started.
What is ngrok ?
ngrok is a cross-platform application that enables developers to expose a local development server to the Internet with minimal effort. The software makes your locally-hosted web server appear to be hosted on a subdomain of ngrok.com, meaning that no public IP or domain name on the local machine is needed.
Installation of ngrok
If you are using windows or mac os you can refer the article below:
If you are using a linux os, you can refer the article below:
Running our web app on a ngrok server
To start ngrok we simply type “ngrok http [port]”, in our case we use port 8000, because it’s the default Django development server port.
ngrok http 8000
you will see the ngrok screen, and your ngrok URL, in my case it’s http://5cedabab7730.ngrok.io, you also have https connection available.
Now go to settings.py and add 5cedabab7730.ngrok.io to ALLOWED_HOSTS. Run your Django development server.
python manage.py runserver
Now your Django App is available to the world under https://5cedabab7730.ngrok.io you can test external APIs, authentications, or share what you working on with your friends.
Note: When you are running ngrok server, you will be getting a different url, so replace https://5cedabab7730.ngrok.io with the url you get.