前提是有Python的环境哦
1.安装Django:pip install django如果有权限问题,sudo pip install django安装
2.创建项目:django-admin startproject login
3.创建APP:django-admin startapp myapp
4.代码可以参照我上一个文章
5.修改settings.py:ALLOWED_HOSTS = ['*']
6.运行:
在项目下运行nohup python manage.py runserver 0.0.0.0:8000 &
然后回车即可
nohup表示输出日志文件到nohup.out中 ; &符号表示后台运行
7.访问:服务器地址:8000端口即可
遇到的问题:
1.报错:
解决办法
1、yum -y install sqlite-devel
2、cd Python-3.5.2 (python源码安装文件解压后的文件夹)
3、./configure --enable-loadable-sqlite-extensions --prefix=/opt/Python352 (--prefix可加可不加)
4、 make && make install
如果这几步还不行,就修改 Python-3.5.2文件夹里的setup.py文件以后,重复第三和第四步:
在 sqlite_inc_paths 中添加sqlite的include 路径
如:
sqlite_inc_paths = [ '/usr/include',
'/usr/include/sqlite',
'/usr/include/sqlite3',
'/usr/local/include',
'/usr/local/include/sqlite',
'/usr/local/include/sqlite3',
'~/share/software/python/sqlite-3.6.20/include', (~/share/software/python/sqlite-3.6.20是sqlite的安装路径)
'~/share/software/python/sqlite-3.6.20/include/sqlite3',
]
二、如果是python2.7出现 import sqlite3 找不到 _sqlite模块的问题,就简单多了
1、# find / -name _sqlite*.so
/usr/lib64/python2.6/lib-dynload/_sqlite3.so
2、# whereis python2.7
python2: /usr/bin/python2.7 /usr/bin/python2 /usr/bin/python2.6 /usr/lib/python2.6 /usr/lib64/python2.6 /usr/local/bin/python2.7 /usr/local/bin/python2.7-config /usr/local/bin/python2 /usr/local/lib/python2.7 /usr/include/python2.6
3、cp /usr/lib64/python2.6/lib-dynload/_sqlite3.so /usr/local/lib/python2.7/lib-dynload/_sqlite3.so
ok,搞定!
2.报错
解决办法:
我们在/usr/lib/python2.7/site-packages/目录下添加一个sitecustomize.py文件,内容如下:
import sys sys.setdefaultencoding('utf-8')