Reputation: 11
I keep on getting this error whenever I run my server locally. This is how allowed hosts is in my .env file ALLOWED_HOSTS=['*'] I have tried adding '127.0.0.1' to the .env file instead of * but nothing seems to be working.Any ideas?
Upvotes: 1
Views: 6439
Reputation: 68
This can be solved by editing settings.py file. Add the IP address without the port number to the ALLOWED_HOSTS array thus:
ALLOWED_HOSTS = ['localhost', '127.0.0.1']
This solved my problem.
Upvotes: 0
Reputation: 472
Django doesn't read .env file by itself. You should care about it.
If you want Django reading environment variables, you should use os.environ.get()
method at your settings.py
. But environment variables must be available for django. Export it at command line or provide .env file to your docker container.
Also, you can use this library: https://django-environ.readthedocs.io/en/latest/
Upvotes: 4