53👍
Edit the following line in your settings.py
file:
ALLOWED_HOSTS = ['127.0.0.1', 'localhost']
Restart your server afterwards
12👍
ALLOWED_HOSTS = ['XXX.iptime.org', 'localhost', '127.0.0.1', 'testserver']
# Application definition
INSTALLED_APPS = [
'polls.apps.PollsConfig',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
- [Django]-How do I display the value of a Django form field in a template?
- [Django]-How do I access the child classes of an object in django without knowing the name of the child class?
- [Django]-How to save pillow image object to Django ImageField?
8👍
Adding ‘testserver’, ‘localhost’, or ‘127.0.0.1’ did not work for me (Django >3.1).
What did was initiating the client with a different server name:
c = Client(SERVER_NAME='localhost')
Note that I got an error mentioning I needed to add ‘testserver’, but that I initiate the client with ‘localhost’.
- [Django]-How to detect Browser type in Django?
- [Django]-Django Admin app or roll my own?
- [Django]-Determine variable type within django template
5👍
You should edit it like that:
ALLOWED_HOSTS = [
‘127.0.0.1’,
‘localhost’,
‘testserver’,
]
- [Django]-Connect to a DB using psycopg2 without password
- [Django]-Django admin: can I define fields order?
- [Django]-What is the default order of a list returned from a Django filter call?
- [Django]-HTML – How to do a Confirmation popup to a Submit button and then send the request?
- [Django]-Docker image error: "/bin/sh: 1: [python,: not found"
- [Django]-NameError: name '_mysql' is not defined after setting change to mysql
- [Django]-Alternative to the deprecated setup_environ() for one-off django scripts?
- [Django]-Django Rest Framework remove csrf
- [Django]-How to get primary keys of objects created using django bulk_create
0👍
settings.py is in read-only mode
ALLOWED_HOSTS = ['127.0.0.1', 'localhost']
this is how to save it
- [Django]-Extend base.html problem
- [Django]-Add an object by id in a ManyToMany relation in Django
- [Django]-How to disable admin-style browsable interface of django-rest-framework?
0👍
Apart from the correct answers, there is an important check which you need to keep in mind. Setting ALLOWED_HOSTS with a single valued tuple will still give you same error, for example if you set it this way:
ALLOWED_HOSTS=('testserver')
It does not work, because you may wanted to make this a tuple but ACTUALLY it is a string in Python, yes thats strange but true! you can read more about tuples here: tuples.
If you want to make it a tuple, you need to add a comma like this:
ALLOWED_HOSTS=('testserver',)
This works as expected.
- [Django]-Django: Want to display an empty field as blank rather displaying None
- [Django]-Where to run collectstatic when deploying django app to heroku using docker?
- [Django]-How to add clickable links to a field in Django admin?
0👍
In settings.py
file, you can simply update ALLOWED_HOSTS = ['*']
. But yes, you can also use solutions provided by others too but to keep it short and simple you can go with this
- [Django]-Return the current user with Django Rest Framework
- [Django]-What does Django's @property do?
- [Django]-Make the first letter uppercase inside a django template