【问题标题】:django development server not workingdjango开发服务器不工作
【发布时间】:2017-11-17 09:03:58
【问题描述】:

问题:

django 开发者服务器没有在 django tutorial 之后提供 Welcome to Django 页面。

遵循的说明:

curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
sudo python3.5 get-pip.py
sudo apt-get install libmysqlclient-dev mysqlclient build-essential python3-dev -y
sudo -H python3.5 -m pip install mysqlclient
sudo -H python3.5 -m pip install Django
cd /mnt/web-server/
django-admin startproject mysite
cd mysite

然后为了启动开发者服务器,我运行了以下命令:

webuser@web-server:/mnt/web-server/mysite$ python3.5 manage.py runserver 8080 &
[1] 1649
webuser@web-server:/mnt/web-server/mysite$ Performing system checks...

System check identified no issues (0 silenced).

You have 13 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions.
Run 'python manage.py migrate' to apply them.

June 15, 2017 - 02:52:22
Django version 1.11.2, using settings 'mysite.settings'
Starting development server at http://127.0.0.1:8080/
Quit the server with CONTROL-C.
^M

转到我的浏览器并尝试访问http://192.168.1.165:8080/ 上的服务器后,我仍然无法让它工作。

观察:

当我尝试使用常用命令查看端口是否正常工作时,我得到的结果是:

webuser@web-server:/mnt/web-server/mysite$ netstat -nlp
(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 127.0.0.1:3306          0.0.0.0:*               LISTEN      -               
tcp        0      0 127.0.0.1:8080          0.0.0.0:*               LISTEN      1651/python3.5  
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      -               
tcp6       0      0 :::22                   :::*                    LISTEN      -               
udp        0      0 0.0.0.0:68              0.0.0.0:*                           -               
Active UNIX domain sockets (only servers)
Proto RefCnt Flags       Type       State         I-Node   PID/Program name    Path
unix  2      [ ACC ]     STREAM     LISTENING     17605    1471/systemd        /run/user/1000/systemd/private
unix  2      [ ACC ]     SEQPACKET  LISTENING     10427    -                   /run/udev/control
unix  2      [ ACC ]     STREAM     LISTENING     13885    -                   /var/run/dbus/system_bus_socket
unix  2      [ ACC ]     STREAM     LISTENING     10168    -                   /run/systemd/private
unix  2      [ ACC ]     STREAM     LISTENING     10173    -                   /run/lvm/lvmetad.socket
unix  2      [ ACC ]     STREAM     LISTENING     10174    -                   /run/systemd/fsck.progress
unix  2      [ ACC ]     STREAM     LISTENING     10176    -                   /run/lvm/lvmpolld.socket
unix  2      [ ACC ]     STREAM     LISTENING     13887    -                   /var/lib/lxd/unix.socket
unix  2      [ ACC ]     STREAM     LISTENING     10180    -                   /run/systemd/journal/stdout
unix  2      [ ACC ]     STREAM     LISTENING     13886    -                   /run/uuidd/request
unix  2      [ ACC ]     STREAM     LISTENING     13888    -                   /run/snapd.socket
unix  2      [ ACC ]     STREAM     LISTENING     13889    -                   /run/snapd-snap.socket
unix  2      [ ACC ]     STREAM     LISTENING     13892    -                   /run/acpid.socket
unix  2      [ ACC ]     STREAM     LISTENING     17257    -                   /var/run/mysqld/mysqld.sock
unix  2      [ ACC ]     STREAM     LISTENING     15992    -                   @ISCSIADM_ABSTRACT_NAMESPACE
webuser@web-server:/mnt/web-server/mysite$ netstat -tulep
(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       User       Inode       PID/Program name
tcp        0      0 localhost:mysql         *:*                     LISTEN      mysql      17256       -               
tcp        0      0 localhost:http-alt      *:*                     LISTEN      webuser    18667       1651/python3.5  
tcp        0      0 *:ssh                   *:*                     LISTEN      root       17212       -               
tcp6       0      0 [::]:ssh                [::]:*                  LISTEN      root       17214       -               
udp        0      0 *:bootpc                *:*                                 root       14154       -               
webuser@web-server:/mnt/web-server/mysite$ lsof -i 
COMMAND    PID    USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
python3.5 1651 webuser    4u  IPv4  18667      0t0  TCP localhost:http-alt (LISTEN)

问题

我在阻止提供静态欢迎页面方面做错了什么?

操作系统信息:

webuser@web-server:/mnt/web-server/mysite$ hostname -I
192.168.1.165 

webuser@web-server:/mnt/web-server/mysite$ python3 --version
Python 3.5.2

webuser@web-server:/mnt/web-server/mysite$ python3 -m pip list --format freeze
chardet==2.3.0
command-not-found==0.3
Django==1.11.2
language-selector==0.1
mysqlclient==1.3.10
pip==9.0.1
pycurl==7.43.0
pygobject==3.20.0
python-apt==1.1.0b1
python-debian==0.1.27
python-systemd==231
pytz==2017.2
requests==2.9.1
setuptools==36.0.1
six==1.10.0
ssh-import-id==5.5
ufw==0.35
unattended-upgrades==0.1
urllib3==1.13.1
virtualenv==15.1.0
wheel==0.29.0

webuser@web-server:/mnt/web-server/mysite$ uname -r
4.4.0-62-generic

webuser@web-server:/mnt/web-server/mysite$ cat /etc/*release*
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=16.04
DISTRIB_CODENAME=xenial
DISTRIB_DESCRIPTION="Ubuntu 16.04.2 LTS"
NAME="Ubuntu"
VERSION="16.04.2 LTS (Xenial Xerus)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 16.04.2 LTS"
VERSION_ID="16.04"
HOME_URL="http://www.ubuntu.com/"
SUPPORT_URL="http://help.ubuntu.com/"
BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"
VERSION_CODENAME=xenial
UBUNTU_CODENAME=xenial

【问题讨论】:

  • 试试python3.5 manage.py runserver 0.0.0.0:8080
  • 它现在只是不是欢迎页面,我得到一个例外DisallowedHost at / Invalid HTTP_HOST header: '192.168.1.165:8080'. You may need to add '192.168.1.165' to ALLOWED_HOSTS. Request Method:
  • ALLOWED_HOSTS = ['192.168.1.165'] 添加到您的settings.py
  • 是的,解决了,@Ykh 您介意将这两个建议作为完整答案发布,我会将其标记为解决方案吗?

标签: django ubuntu python-3.5


【解决方案1】:

尝试python3.5 manage.py runserver 0.0.0.0:8080 并将ALLOW_HOSTS=['192.xxx.xxx.xxx'] 添加到您的settings.py

python3.5 manage.py runserver 0.0.0.0:8080将django分配给你本地计算机的ip地址,你可以通过http://localhost/http://your_ip_address/访问django

python3.5 manage.py runserver 8080 django 只能通过http://localhost/ 访问。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-03-02
    • 1970-01-01
    • 2011-01-06
    • 1970-01-01
    • 1970-01-01
    • 2022-01-15
    • 2017-10-25
    相关资源
    最近更新 更多