How to access the local Django webserver from outside world

前端 未结 9 1680
天命终不由人
天命终不由人 2020-12-02 04:06

I followed the instructions here to run Django using the built-in webserver and was able to successfully run it using python manage.py runserver. If I access 1

相关标签:
9条回答
  • 2020-12-02 04:37

    For AWS users.

    I had to use the following steps to get there.

    1) Ensure that pip and django are installed at the sudo level

    • sudo apt-get install python-pip
    • sudo pip install django

    2) Ensure that security group in-bound rules includ http on port 80 for 0.0.0.0/0

    • configured through AWS console

    3) Add Public IP and DNS to ALLOWED_HOSTS

    • ALLOWED_HOSTS is a list object that you can find in settings.py
    • ALLOWED_HOSTS = ["75.254.65.19","ec2-54-528-27-21.compute-1.amazonaws.com"]

    4) Launch development server with sudo on port 80

    • sudo python manage.py runserver 0:80

    Site now available at either of the following (no need for :80 as that is default for http):

    • [Public DNS] i.e. ec2-54-528-27-21.compute-1.amazonaws.com
    • [Public IP] i.e 75.254.65.19
    0 讨论(0)
  • install ngrok in terminal

    sudo apt-get install -y ngrok-client
    

    after that run:

    ngrok http 8000
    or 
    ngrok http example.com:9000 
    
    0 讨论(0)
  • 2020-12-02 04:47

    just do this:

    python manage.py runserver 0:8000
    

    by the above command you are actually binding it to the external IP address. so now when you access your IP address with the port number, you will be able to access it in the browser without any problem.

    just type in the following in the browser address bar:

    <your ip address>:8000
    

    eg:

    192.168.1.130:8000
    

    you may have to edit the settings.py add the following in the settings.py in the last line:

    ALLOWED_HOSTS = ['*']
    

    hope this will help...

    0 讨论(0)
提交回复
热议问题