Sometimes when developing our Django application, we need to make it publicly accessible or use https, for example when testing oauth authentication sometimes https is enforced, or when testing Shopify webhooks (where the request is executed on Shopify server, so we need to make it publicly available), or simple when we want to share it with a friend with out deploying it live. To achive it We can use ngrok to redirect what you are running on localhost to publicly available ngrok URL. Let’s get started.
on mac we can install it simply with brew.
brew cask install ngrok
For windows we can download it from here.
to start ngrok we simply type “ngrok http [port]“, in our case we use port 8000, beacuse 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.