django开发服务器无法正常工作

时间:2017-06-15 03:05:06

标签: django ubuntu python-3.5

问题:

django开发者服务器未在此django tutorial之后提供欢迎使用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

1 个答案:

答案 0 :(得分:2)

尝试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才能访问http://localhost/ django