Python Django 不允许的主机
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/41755223/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Disallowed Host at Django
提问by Stacker
I'm just starting out with Django for the first time. So I create a django project and run the command
我是第一次开始使用 Django。所以我创建了一个 django 项目并运行命令
python3 manage.py runserver 0.0.0.0:8000
Instead of getting the expected django homepage, I get the following error message,
我收到以下错误消息,而不是获得预期的 django 主页,
DisallowedHost at /
Invalid HTTP_HOST header: '0.0.0.0:8000'. You may need to add '0.0.0.0' to ALLOWED_HOSTS.
Request Method: GET
Request URL: http://0.0.0.0:8000/
Django Version: 1.10.5
Exception Type: DisallowedHost
Exception Value:
Invalid HTTP_HOST header: '0.0.0.0:8000'. You may need to add '0.0.0.0' to ALLOWED_HOSTS.
Exception Location: /usr/local/lib/python3.5/site-packages/django/http/request.py in get_host, line 113
Python Executable: /usr/local/opt/python3/bin/python3.5
Python Version: 3.5.2
I haven't yet scratched the surface of django, so would appreciate some help as to how to fix this?
我还没有触及 django 的表面,所以希望得到一些关于如何解决这个问题的帮助?
回答by Bobby
literally as the error suggested! go ahead and add the line
字面上的错误建议!继续添加该行
0.0.0.0
to the ALLOWED_HOSTS
in your settings.py
0.0.0.0
到ALLOWED_HOSTS
你settings.py
The error info is quite explicit. It should solve the problem right away.
错误信息非常明确。它应该立即解决问题。
回答by Robert Seddon-Smith
I too had problems with this and it is not easy for a beginner to fix. Here below is the sequence required:
我也遇到了这个问题,初学者很难解决。以下是所需的顺序:
First find your settings.py file, which is located:
首先找到您的 settings.py 文件,该文件位于:
projectName/projectName/settings.py
项目名称/项目名称/settings.py
You can also find it using: find -name "settings.py" - likely you will have only one!
您也可以使用以下命令找到它: find -name "settings.py" - 您可能只有一个!
Once you have found this, you need to open it in a text editor and change the line
找到后,您需要在文本编辑器中打开它并更改行
ALLOWED_HOSTS =[ ] to ALLOWED_HOSTS =['your.host.ip.address'] - include the ' ' and the [ ] then save. You will have to re-start the server to get this to work eg:
ALLOWED_HOSTS =[ ] 到 ALLOWED_HOSTS =['your.host.ip.address'] - 包括 ' ' 和 [ ] 然后保存。您必须重新启动服务器才能使其正常工作,例如:
python manage.py runserver your.host.ip.address:8000
If you get a syntax error, make sure you have something that looks like:
如果您收到语法错误,请确保您有以下内容:
ALLOWED_HOSTS =['192.168.1.200']
or whatever your ip address is.
ALLOWED_HOSTS =['192.168.1.200']
或无论您的 IP 地址是什么。
回答by Antonio
1- run
1-运行
ifconfig check you ip address, and you should add the ip to this lone: ALLOWED_HOSTS =['you IP address goes here']
ifconfig 检查你的 ip 地址,你应该将 ip 添加到这个单独的:ALLOWED_HOSTS =['你的 IP 地址在这里']
2- run:
2-运行:
python manage.py your-ip:8000
python manage.py your-ip:8000
3- go to your browser and check you ip:8000
3-转到您的浏览器并检查您的ip:8000
回答by SALAH EDDINE ELGHARBI
1.You can also find it using: find -name "SETTINGS.py" - likely you will have only one!
1.您也可以使用以下命令找到它: find -name "SETTINGS.py" - 您可能只有一个!
2.Once you have found this, you need to open it in a text editor and change the line in the insetting File
2.一旦你找到这个,你需要在文本编辑器中打开它并更改插入文件中的行
ALLOWED_HOSTS =['Your_compte_pythonanywher.pythonanywhere.com']