[PYTHON] Exclusive release of the django app using ngrok

Purpose

To publish the django app in a limited and easy way Use the django app that is running locally using ngrok from the outside.

What is ngrok

ngrok is a tool that allows you to access a server running on localhost from outside the LAN. For details → How to use ngrok (windows, mac)

Start ngrok

Download ngrok from ↓ and unzip it in any location. ngrok

Launch ngrok.exe ngrok.exe.png

ngrok settings

If you start django by default, the port number will be 8000.

System check identified no issues (0 silenced).
April 22, 2020 - 17:50:03
Django version 3.0.3, using settings 'project.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.

To process the app URL http://127.0.0.1:8000/ with ngrok On the ngrok terminal, enter ngrok http 8000 and execute. It is also possible to pass an argument to ngrok.exe and execute it. ngrok.exe http 8000 ngrok.exe2.png

Forwardingに表示されてるxxxxx.ngrok.io/アプリ名で外部アクセスができる。 The app name is the application name defined in apps.py.

django settings

On the djnago side, it is necessary to allow access from ngrok, and add '.ngrok.io' to ʻALLOWED_HOSTS`. Since the character string before **. ngrok ** is randomly generated each time it is started, only access from ngrok is allowed so as not to affect it at startup.

settings.py


ALLOWED_HOSTS = ['.ngrok.io']

If ALLOWED_HOSTS is not supported, the following error will occur.

DisallowedHost at /app/
Invalid HTTP_HOST header: 'xxxxx.ngrok.io'. You may need to add 'xxxxx.ngrok.io' to ALLOWED_HOSTS.

Request Method:	GET
Request URL:	http://xxxxx.ngrok.io/app/
Django Version:	3.0.3
Exception Type:	DisallowedHost
Exception Value:	
Invalid HTTP_HOST header: 'xxxxx.ngrok.io'. You may need to add 'xxxxx.ngrok.io' to ALLOWED_HOSTS.
・
・
・

Recommended Posts

Exclusive release of the django app using ngrok
The meaning of ".object" in Django
Flow of getting the result of asynchronous processing using Django and Celery
Consider the description of Dockerfile (Django + MySQL②)
Heroku deployment of the first Django app that beginners are addicted to
I tried the asynchronous server of Django 3.0
Understand the benefits of the Django Rest Framework
How to check the version of Django
Development of MTG card evaluation posting site ~ Django app release in 5 weeks ~
Deploy the Django app on Heroku [Part 2]
Deploy the Django app on Heroku [Part 1]
The story of using mysqlclient because PyMySQL cannot be used with Django 2.2
Consider the description of docker-compose.yml (Django + MySQL ③)
Estimating the effect of measures using propensity scores
Check the type of the variable you are using
I checked the session retention period of django
Operate the schedule app using python from iphone
Try using the collections module (ChainMap) of python3
The story of viewing media files in Django
Find the geometric mean of n! Using Python
Determine the number of classes using the Starges formula
I tried using the image filter of OpenCV
Check the status of your data using pandas_profiling
Scraping the winning data of Numbers using Docker
Calculation of the shortest path using the Monte Carlo method
Explanation of the concept of regression analysis using python Part 2
Cut a part of the string using a Python slice
[CRUD] [Django] Create a CRUD site using the Python framework Django ~ 1 ~
Create a Todo app with the Django REST framework
Drawing on Jupyter using the plot function of pandas
The pain of gRPC using Python. November 2019. (Personal memo)
DJango Note: From the beginning (using a generic view)
Explanation of the concept of regression analysis using Python Part 1
[Django] Change the Default IP address of the runserver command
I tried using the API of the salmon data project
[Django Rest Framework] Customize the filter function using Django-Filter
[CRUD] [Django] Create a CRUD site using the Python framework Django ~ 2 ~
Let's analyze the emotions of Tweet using Chainer (2nd)
Explanation of the concept of regression analysis using Python Extra 1
Miscellaneous notes about deploying the django app on Heroku
[Django 2.2] Sort and get the value of the relation destination
Study from the beginning of Python Hour8: Using packages
Let's analyze the sentiment of Tweet using Chainer (1st)
Using the LibreOffice app in Python (1) Where are the macros?
The story of using circleci to build manylinux wheels
[CRUD] [Django] Create a CRUD site using the Python framework Django ~ 3 ~
[CRUD] [Django] Create a CRUD site using the Python framework Django ~ 4 ~
[CRUD] [Django] Create a CRUD site using the Python framework Django ~ 5 ~
[Python] Let's change the URL of the Django administrator site