django自带的server 让外网主机访问方法
作者:ZhangQ_ 时间:2023-06-03 22:59:50
命令:
Python manage.py runserver
改为
python manage.py runserver 0.0.0.0:80
外网和127.0.0.1都能够访问
可能会出现DisallowedHost at / Invalid HTTP_HOST header:
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的项目了;
来源:https://blog.csdn.net/qq_25560423/article/details/56290505
标签:django,外网,访问,server
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
浅谈php自定义错误日志
2023-11-14 10:59:40
Python判断一个文件夹内哪些文件是图片的实例
2023-08-18 01:22:44
Python 使用input同时输入多个数的操作
2023-09-23 22:36:42
![](https://img.aspxhome.com/file/2023/8/107138_0s.jpg)
PHP把空格、换行符、中文逗号等替换成英文逗号的正则表达式
2024-04-10 10:56:49
![](https://img.aspxhome.com/file/2023/0/136850_0s.png)
Python进度条的制作代码实例
2022-01-01 23:17:34
MYSQL中binlog优化的一些思考汇总
2024-01-23 01:58:25
![](https://img.aspxhome.com/file/2023/3/96493_0s.jpg)
详解JS如何判断对象上是否存在某个属性
2024-04-16 09:49:28
Python生命游戏实现原理及过程解析(附源代码)
2023-07-16 18:02:13
![](https://img.aspxhome.com/file/2023/6/60706_0s.gif)
Python PyQt5学习之自定义信号
2022-01-06 12:03:52
![](https://img.aspxhome.com/file/2023/7/72887_0s.png)
浅谈Python函数式编程的返回函数与匿名函数
2021-02-22 13:40:36
检测SqlServer数据库是否能连接的小技巧
2024-01-21 04:01:28
![](https://img.aspxhome.com/file/2023/3/110113_0s.png)
详解使用PyInstaller将Pygame库编写的小游戏程序打包为exe文件
2023-11-10 13:20:31
![](https://img.aspxhome.com/file/2023/2/109992_0s.png)
MySQL身份认证漏洞 升级到5.5.24可修正
2012-07-11 15:54:09
Python定时库APScheduler的原理以及用法示例
2022-05-09 05:45:43
![](https://img.aspxhome.com/file/2023/7/80817_0s.jpg)
mysql community server 8.0.12安装配置方法图文教程
2024-01-21 19:28:04
关于Python中的if __name__ == __main__详情
2022-05-04 10:16:28
![](https://img.aspxhome.com/file/2023/2/127322_0s.png)
python使用scapy模块实现ping扫描的过程详解
2023-07-07 05:29:24
![](https://img.aspxhome.com/file/2023/6/135086_0s.png)
python实现马丁策略回测3000只股票的实例代码
2023-03-02 01:12:29
![](https://img.aspxhome.com/file/2023/3/109503_0s.gif)
python对RabbitMQ的简单入门使用教程
2021-01-13 17:53:44
![](https://img.aspxhome.com/file/2023/4/93734_0s.jpg)
JS中不为人知的五种声明Number的方式简要概述
2024-04-29 13:13:43
![](https://img.aspxhome.com/file/2023/8/132828_0s.png)