centos6 python3 django-uwsgi-nginx 环境搭建01-之Django

前端之家收集整理的这篇文章主要介绍了centos6 python3 django-uwsgi-nginx 环境搭建01-之Django前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

1.安装django

pip3 install django

2.建立一个项目

django-admin.py startproject myblog

生成相应的项目结构及文件

[root@VM_11_215_centos myblog]# ls
manage.py  myblog
[root@VM_11_215_centos myblog]# cd myblog/
[root@VM_11_215_centos myblog]# ls
__init__.py  __pycache__  settings.py  urls.py  wsgi.py

3.进入myblog(有mange.py的目录),启动项目(服务)

python manage.py runserver 8000

提示错误:却少模块

django.core.exceptions.ImproperlyConfigured: Error loading either 
pysqlite2 or sqlite3 modules (tried in that order): 
No module named '_sqlite3'

解决方法

解决:
1,首先安装 sqlite-devel
yum install sqlite-devel

2,重新编译安装Python
./configure
make
make install

4.发现按照3中的命令来启动服务,通过外网是不能访问的,因为8000端口未对外开放以及监听对ip地址也有问题。

解决方法

开发防火墙的8000端口

打开防火墙配置文件
vim /etc/sysconfig/iptables
添加下面的语句
-A INPUT -p tcp -m tcp --dport 8000 -j ACCEPT

然后重启防火墙:
[root@VM_11_215_centos ~]# /etc/init.d/iptables restart
iptables:将链设置为政策 ACCEPT:filter                    [确定]
iptables:清除防火墙规则:                                 [确定]
iptables:正在卸载模块:                                   [确定]
iptables:应用防火墙规则:                                 [确定]
[root@VM_11_215_centos ~]#

再次启动服务,需要加上本机的内网地址(腾讯云--为什么不知道):

[root@VM_11_215_centos myblog]# python manage.py runserver 10.***.***.***:8000
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.

February 07,2017 - 07:46:25
Django version 1.10.5,using settings 'myblog.settings'
Starting development server at http://10.***.***.***:8000/

外网访问正常

原文链接:https://www.f2er.com/centos/378849.html

猜你在找的CentOS相关文章