Invalid http_host header
Question:
I am trying to develop a website using Django framework and launched using DigitalOcean.com and deployed the necessary files into django-project.
I had to include static files into Django-project and After collecting static files, I tried to refresh my ip
I am including the tutorials which I have used to create the website.
https://www.pythonprogramming.net/django-web-server-publish-tutorial/
I am getting the following error :
DisallowedHost at / Invalid HTTP_HOST header: ‘198.211.99.20’. You may
need to add u’198.211.99.20′ to ALLOWED_HOSTS.
Can somebody help me to fix this ? This is my first website using Django framework.
Answers:
The error log is straightforward. As it suggested,You need to add 198.211.99.20 to your ALLOWED_HOSTS
setting.
In your project settings.py file,set ALLOWED_HOSTS
like this :
ALLOWED_HOSTS = ['198.211.99.20', 'localhost', '127.0.0.1']
For further reading
read from here.
settings.py
ALLOWED_HOSTS = ['*'] // if you are in dev or docker
Edited
Ok guys, dont do this in production if you are not using docker, just put the IP addr.
Grettings
In your project settings.py file,set ALLOWED_HOSTS like this :
ALLOWED_HOSTS = ['62.63.141.41', 'namjoosadr.com']
and then restart your apache. in ubuntu:
/etc/init.d/apache2 restart
if no other answer work you can try modifying manage.py and add this three lines
from django.utils.regex_helper import _lazy_re_compile
import django.http.request
django.http.request.host_validation_re = _lazy_re_compile(r"[a-zA-z0-9.:]*")
to end up having something like this:
import os
import sys
from django.utils.regex_helper import _lazy_re_compile
import django.http.request
django.http.request.host_validation_re = _lazy_re_compile(r"[a-zA-z0-9.:]*")
def main():
"""Run administrative tasks."""
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'project01.settings')
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)
if __name__ == '__main__':
main()
as it is explained in this post: How to Solve "The domain name provided is not valid according to RFC 1034/1035" in Django during Development
I am trying to develop a website using Django framework and launched using DigitalOcean.com and deployed the necessary files into django-project.
I had to include static files into Django-project and After collecting static files, I tried to refresh my ip
I am including the tutorials which I have used to create the website.
https://www.pythonprogramming.net/django-web-server-publish-tutorial/
I am getting the following error :
DisallowedHost at / Invalid HTTP_HOST header: ‘198.211.99.20’. You may
need to add u’198.211.99.20′ to ALLOWED_HOSTS.
Can somebody help me to fix this ? This is my first website using Django framework.
The error log is straightforward. As it suggested,You need to add 198.211.99.20 to your ALLOWED_HOSTS
setting.
In your project settings.py file,set ALLOWED_HOSTS
like this :
ALLOWED_HOSTS = ['198.211.99.20', 'localhost', '127.0.0.1']
For further reading
read from here.
settings.py
ALLOWED_HOSTS = ['*'] // if you are in dev or docker
Edited
Ok guys, dont do this in production if you are not using docker, just put the IP addr.
Grettings
In your project settings.py file,set ALLOWED_HOSTS like this :
ALLOWED_HOSTS = ['62.63.141.41', 'namjoosadr.com']
and then restart your apache. in ubuntu:
/etc/init.d/apache2 restart
if no other answer work you can try modifying manage.py and add this three lines
from django.utils.regex_helper import _lazy_re_compile
import django.http.request
django.http.request.host_validation_re = _lazy_re_compile(r"[a-zA-z0-9.:]*")
to end up having something like this:
import os
import sys
from django.utils.regex_helper import _lazy_re_compile
import django.http.request
django.http.request.host_validation_re = _lazy_re_compile(r"[a-zA-z0-9.:]*")
def main():
"""Run administrative tasks."""
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'project01.settings')
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)
if __name__ == '__main__':
main()
as it is explained in this post: How to Solve "The domain name provided is not valid according to RFC 1034/1035" in Django during Development