问题背景:
目前在使用python 中的 django.test Client() 类进行客户端测试,遇到报错信息‘Invalid HTTP_HOST header: 'testserver'. You may need to add 'testserver' to ALLOWED_HOSTS.’ 报错,无法解决;
1、Django -v:1.10.3
2、python -v:python3
3、web项目已经搭建成功:首页地址 [color=rgb(0, 105, 214) !important]http://127.0.0.1:8000/index/ 可正常访问;
使用 Django内置 Client()类模拟get() 和 post()请求方式进行客户端验证;
cmd.exe
解决方法:
1、setting.py 中设置
DEBUG=True
ALLOWED_HOSTS = ['*'] / ALLOWED_HOSTS = ['127.0.0.1','localhost','testserver']
(因为看到网上说 当DEBUG为True并且ALLOWED_HOSTS为空时,主机将针对['localhost','127.0.0.1','[:: 1]']进行验证。)
DEBUG=False
ALLOWED_HOSTS = ['*'] / ALLOWED_HOSTS = ['127.0.0.1','localhost','testserver']
以上均无效。跪求大神帮忙解答,在线等……
欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/) | Powered by Discuz! X3.2 |