脚本之家,脚本语言编程技术及教程分享平台!
分类导航

Python|VBS|Ruby|Lua|perl|VBA|Golang|PowerShell|Erlang|autoit|Dos|bat|

服务器之家 - 脚本之家 - Python - django自带的server 让外网主机访问方法

django自带的server 让外网主机访问方法

2021-02-21 00:14ZhangQ_ Python

今天小编就为大家分享一篇django自带的server 让外网主机访问方法。具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧

命令:

?
1
Python manage.py runserver

改为

?
1
python manage.py runserver 0.0.0.0:80

外网和127.0.0.1都能够访问

可能会出现DisallowedHost at / Invalid HTTP_HOST header:

?
1
2
3
4
5
6
7
8
9
10
11
12
DisallowedHost at /
Invalid HTTP_HOST header: ‘x:8000'. You may need to add u'10.211.55.6' to ALLOWED_HOSTS.
 
Request Method: GET
Request URL: http://x:8000/
Django Version: 1.10.4
Exception Type: DisallowedHost
Exception Value:
Invalid HTTP_HOST header: ‘10.211.55.6:8000'. You may need to add u'10.211.55.6' to ALLOWED_HOSTS.
Exception Location: /usr/lib/python2.7/site-packages/django/http/request.py in get_host, line 113
Python Executable: /usr/bin/python
Python Version:

1 以上时我访问请求的时候出现的,原因在于Django框架中的创建的一个项目的时候,

2 跑下这个命令:Python manage.py runserver ip:8000

3 然后在我本机的浏览器中写入上述IP和端口请求过去:http://ip:8000

4 于是就出现了最上面的那个问题;

5 于是就去django-admin.py startproject project-name创建的项目中去修改 setting.py 文件:

ALLOWED_HOSTS = [‘*'] #在这里请求的host添加了*

6 于是就成功的访问到了Django的项目了;

以上这篇django自带的server 让外网主机访问方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持服务器之家。

原文链接:https://blog.csdn.net/qq_25560423/article/details/56290505

延伸 · 阅读

精彩推荐