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

    ......

  • 相关阅读:
    Win10 x64 + CUDA 10.0 + cuDNN v7.5 + TensorFlow GPU 1.13 安装指南
    工作十一年总结
    Anaconda3 指南
    Win Linux 双系统安装指南
    OBS 录制视频 自己留存
    React Starter Kit 中文文档
    .NET Framework 系统版本支持表
    Hyper-V和其他虚拟机共存 【转】
    Docker入门03——Container
    Docker入门02——Dockerfile详解
  • 原文地址:https://www.cnblogs.com/studyddup0212/p/8930258.html
Copyright © 2011-2022 走看看