To publish the django app in a limited and easy way Use the django app that is running locally using ngrok from the outside.
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)
Download ngrok from ↓ and unzip it in any location. ngrok
Launch ngrok.exe
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
Forwardingに表示されてるxxxxx.ngrok.io/アプリ名
で外部アクセスができる。
The app name is the application name defined in apps.py.
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