Recall & Review
beginner
What is the purpose of the
ALLOWED_HOSTS setting in Django?It defines a list of host/domain names that the Django site can serve. This helps protect against HTTP Host header attacks by only allowing requests from specified hosts.
Click to reveal answer
beginner
How do you configure
ALLOWED_HOSTS to allow your Django app to serve requests from example.com and www.example.com?Set
ALLOWED_HOSTS = ['example.com', 'www.example.com'] in your settings.py file.Click to reveal answer
intermediate
What happens if
ALLOWED_HOSTS is empty in a production Django app?Django will raise a
DisallowedHost error and refuse to serve requests, because no hosts are allowed. This prevents serving requests from unknown or malicious hosts.Click to reveal answer
intermediate
Why should you avoid setting
ALLOWED_HOSTS = ['*'] in production?Using
'*' allows any host, which removes protection against Host header attacks and can expose your app to security risks.Click to reveal answer
intermediate
How can you allow localhost and all subdomains of
example.com in ALLOWED_HOSTS?Set
ALLOWED_HOSTS = ['localhost', '127.0.0.1', '.example.com']. The dot before example.com allows all subdomains like api.example.com.Click to reveal answer
What type of values does
ALLOWED_HOSTS accept?✗ Incorrect
ALLOWED_HOSTS must be a list of strings with host or domain names your app will serve.What error does Django raise if a request comes from a host not in
ALLOWED_HOSTS?✗ Incorrect
Django raises
DisallowedHost to block requests from unauthorized hosts.Which setting is the safest for
ALLOWED_HOSTS in production?✗ Incorrect
Only listing your real domain names protects your app from host header attacks.
How do you allow all subdomains of a domain in
ALLOWED_HOSTS?✗ Incorrect
A leading dot like '.example.com' allows all subdomains such as 'api.example.com'.
If you want to test locally, which host should you add to
ALLOWED_HOSTS?✗ Incorrect
Adding both 'localhost' and '127.0.0.1' covers common local testing hosts.
Explain why the
ALLOWED_HOSTS setting is important for Django security and how to configure it properly.Think about what happens if a request comes from an unknown domain.
You got /5 concepts.
Describe how to set
ALLOWED_HOSTS for a Django app running locally and on a production domain with subdomains.Consider both local and live environments.
You got /4 concepts.