zoukankan      html  css  js  c++  java
  • django error: DisallowedHost: Invalid HTTP_HOST header: ''. You may need to add u'' to ALLOWED_HOST

    测试环境:

    [root@nanx-lli ~]# lsb_release -a
    LSB Version: :core-4.1-amd64:core-4.1-noarch
    Distributor ID: CentOS
    Description: CentOS Linux release 7.4.1708 (Core)
    Release: 7.4.1708
    Codename: Core


    [root@nanx-lli ~]# python
    Python 2.7.5 (default, Aug 4 2017, 00:39:18)
    [GCC 4.8.5 20150623 (Red Hat 4.8.5-16)] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import django
    >>> django.VERSION
    (1, 11, 12, u'final', 0)

    [root@nanx-lli HelloWorld]# pwd
    /root/HelloWorld/HelloWorld
    [root@nanx-lli HelloWorld]# tree
    .
    ├── __init__.py
    ├── __init__.pyc
    ├── settings.py
    ├── settings.pyc
    ├── urls.py
    ├── urls.pyc
    ├── view.py
    ├── view.pyc
    ├── wsgi.py
    └── wsgi.pyc

    0 directories, 10 files
    [root@nanx-lli HelloWorld]# cat view.py

    from django.http import HttpResponse

    def hello(request):
    return HttpResponse("Hello world!")

    问题:

    PC: 10.245.36.203上通过chrome访问,http://10.245.242.221:8000时报错,并且此时在Linux上同时有错误log显示:

    Invalid HTTP_HOST header: '10.245.242.221:8000'. You may need to add u'10.245.242.221' to ALLOWED_HOSTS.

    解决方案:

    添加10.245.242.221到allowed_hosts.

    修改setting.py

    ......

    # SECURITY WARNING: don't run with debug turned on in production!
    DEBUG = True

    ALLOWED_HOSTS = ['10.245.242.221']

    # Application definition

    ......

  • 相关阅读:
    C# 读取JSON
    checkbox与说明文字无法对齐的问题
    C#判断一个string是否为数字
    C# 调用系统winmm.dll 播放音乐wav mp3
    C#导出EXCEL的几种方法
    C#遍历DataSet中数据的几种方法总结
    cookie 简单用法
    JQGrid 在页面加载时展开SubGrid
    Echarts 设置地图上文字大小及颜色
    Echarts 地图上显示数值
  • 原文地址:https://www.cnblogs.com/studyddup0212/p/8930258.html
Copyright © 2011-2022 走看看