Python:Install Django on RHEL7.1 and Run a Demo Project
以下代码罗列如何在RHEL7.1上安装Python的Django WEB开发框架:
一、安装PIP支持:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
[root@adamhuanlinux python]# pwd /software/python [root@adamhuanlinux python]# ls [root@adamhuanlinux python]# cp /root/Downloads/get-pip.py . [root@adamhuanlinux python]# ls get-pip.py [root@adamhuanlinux python]# du -sh * 1.4M get-pip.py [root@adamhuanlinux python]# python2.7 get-pip.py Collecting pip /tmp/tmpxqSmOs/pip.zip/pip/_vendor/requests/packages/urllib3/util/ssl_.py:79: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning. Downloading pip-6.1.1-py2.py3-none-any.whl (1.1MB) 100% |████████████████████████████████| 1.1MB 283kB/s Installing collected packages: pip Successfully installed pip-6.1.1 [root@adamhuanlinux python]# |
二、通过PIP安装Django
1 2 3 4 5 6 7 8 9 |
[root@adamhuanlinux python]# pip install django Collecting django /usr/lib/python2.7/site-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:79: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning. InsecurePlatformWarning Downloading Django-1.8.1-py2.py3-none-any.whl (6.2MB) 100% |████████████████████████████████| 6.2MB 36kB/s Installing collected packages: django Successfully installed django-1.8.1 [root@adamhuanlinux python]# |
三、创建一个Django的项目
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
[root@adamhuanlinux python]# django-admin.py startproject webdemo [root@adamhuanlinux python]# ls get-pip.py webdemo [root@adamhuanlinux python]# tree webdemo/ webdemo/ ├── manage.py └── webdemo ├── __init__.py ├── settings.py ├── urls.py └── wsgi.py 1 directory, 5 files [root@adamhuanlinux python]# |
四、运行第三步创建的Django项目
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
[root@adamhuanlinux webdemo]# pwd /software/python/webdemo [root@adamhuanlinux webdemo]# ls db.sqlite3 manage.py webdemo [root@adamhuanlinux webdemo]# [root@adamhuanlinux webdemo]# python2.7 manage.py runserver Performing system checks... System check identified no issues (0 silenced). You have unapplied migrations; your app may not work properly until they are applied. Run 'python manage.py migrate' to apply them. May 07, 2015 - 10:03:55 Django version 1.8.1, using settings 'webdemo.settings' Starting development server at http://127.0.0.1:8000/ Quit the server with CONTROL-C. Error: That port is already in use. [root@adamhuanlinux webdemo]# |
可以看到,Django的反馈信息显示:8000的端口被占用。
查看系统信息,确实如此:
1 2 3 |
[root@adamhuanlinux webdemo]# netstat -tupln | grep --color 8000 tcp6 0 0 127.0.0.1:8000 :::* LISTEN 2868/java [root@adamhuanlinux webdemo]# |
更换端口启动:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
[root@adamhuanlinux webdemo]# python2.7 manage.py runserver --noreload 168.0.1.190:9090 & [2] 19495 [1] Killed python2.7 manage.py runserver --noreload 9090 [root@adamhuanlinux webdemo]# Performing system checks... System check identified no issues (0 silenced). You have unapplied migrations; your app may not work properly until they are applied. Run 'python manage.py migrate' to apply them. May 07, 2015 - 10:13:13 Django version 1.8.1, using settings 'webdemo.settings' Starting development server at http://168.0.1.190:9090/ Quit the server with CONTROL-C. [root@adamhuanlinux webdemo]# |
Django的服务启动成功。
浏览器访问:http://168.0.1.190:9090/
————————————————————————————————
Done。