Why is Django throwing error “DisallowedHost at /”?

后端 未结 5 1359
难免孤独
难免孤独 2020-12-13 23:19

I am setting up my own Django server using this Digital Ocean tutorial. I created the Django framework following each step, and ran the server using this command:

         


        
5条回答
  •  难免孤独
    2020-12-14 00:02

    In your settings.py, there is a list called ALLOWED_HOSTS. You need to add the IP address you see in the error to that list:

    ALLOWED_HOSTS = ['XX.XX.XX.XX']

    Note: only add the IP address, and not the port (e.g., 127.0.0.1 and not 127.0.0.1:8000)

    Explanation:

    Django checks the Host header of the HTTP request for a url/ip address that is within the allowed hosts.

    From the django website:

    This is a security measure to prevent HTTP Host header attacks, which are possible even under many seemingly-safe web server configurations.

    https://docs.djangoproject.com/en/dev/ref/settings/#allowed-hosts

提交回复
热议问题