发布于 2014-11-16 03:15:07 | 1125 次阅读 | 评论: 0 | 来源: 网友投递

这里有新鲜出炉的Django教程,程序狗速度看过来!

Django Python WEB开发框架

Django是一个开放源代码的Web应用框架,由Python写成。采用了MVC的软件设计模式,即模型M,视图V和控制器C。它最初是被开发来用于管理劳伦斯出版集团旗下的一些以新闻内容为主的网站的,即是CMS(内容管理系统)软件。并于2005年7月在BSD许可证下发布。这套框架是以比利时的吉普赛爵士吉他手Django Reinhardt来命名的。


本文为大家讲解的是阿里云 centos 服务器的环境配置与 django web应用框架的安装和部署详解,感兴趣的同学参考下.

1. 免密码登陆

# 本机生成密钥, 并将 pub 复制到阿里云服务器上
$ ssh-keygen -t rsa -P ''  # -P表示密码,-P '' 就表示空密码
$ scp ~/.ssh/FILENAME.pub root@server_ip:/root

# 阿里云服务器上将 pub 放入 authorized_keys 中
# cat FILENAME.pub >> ~/.ssh/authorized_keys
# chmod 600 ~/.ssh/authorized_keys
 

2. yum

默认的环境并不 OK.

1) 运行出错提示    No module named yum

解决方案: #vi /usr/bin/yum 将 #!/usr/bin/python 修改为  #!/usr/bin/python2.4

2) 下载yum的配置源

mkdir /etc/yum.repos.d/
cd /etc/yum.repos.d/
wget http://docs.linuxtone.org/soft/lemp/CentOS-Base.repo

3) 运行yum makecache生成缓存

若重新安装 yum

查看yum包  rpm -qa|grep yum 
卸载  rpm -qa|grep yum|xargs rpm -e --nodeps 
安装:

1) 下载安装所需的三个文件, 下载地址: http://centos.ustc.edu.cn/centos/5/os/x86_64/CentOS/

yum-3.2.22-40.el5.centos.noarch.rpm
yum-fastestmirror-1.1.16-21.el5.centos.noarch.rpm
yum-metadata-parser-1.1.2-4.el5.x86_64.rpm

2)  安装命令

rpm -ivh yum-*

注意:yum和yum-fastestmirror相互依赖,所以需要同时安装。

3) 恢复 /etc/yum.conf 文件, 一般卸载时会自动备份.

3. 开发环境依赖包更新

$ yum update
$ yum -y install gcc g++ autoconf
$ yum -y install openssl openssl-devel zlib zlib-devel

4. python

手动编译安装 Python, 官网下载源码即可.

./configure  --enable-shared  # if not, error -- libpython2.7.a:  could not read symbols: Bad value
make
make install

此时运行 python 可能报错: 

python: error while loading shared  libraries: libpython2.7.so.1.0:

  cannot open shared object file: No such file or

解决方案:

 
$ vim /etc/ld.so.conf.d/python2.7.conf
# 加入内容:
/usr/local/lib

#保存退出后运行:
$ ldconfig
 

pip 与 库. 源码 setup.py 安装 setuptools 与 pip

yum install -y  python-setuptools python-devel
sudo easy_install -U distribute

5. 手动安装 git

http://distfiles.macports.org/git/ 下载最新 git
 
$ yum install gettext-devel

$ wget http://distfiles.macports.org/git/git-2.1.1.tar.gz
$ tar zxvf git-2.1.1.tar.gz
$ cd git-2.1.1
$ autoconf 
$ ./configure
$ make 
$ make install

6. MySQL

# yum install mysql mysql-server
# mysql_secure_installation  # secure settings

开机自动启动

# chkconfig --levels 235 mysqld on
# service mysqld restart

7. apache2 与 mod_wsgi

# yum install httpd httpd-devel

# chkconfig --levels 235 httpd on
# service httpd restart

源码安装 mod_wsgi https://github.com/GrahamDumpleton/mod_wsgi

配置

 
WSGIScriptAlias / /var/www/django_server/wsgi.py

<Directory "/var/www/django_server/static/">
           Order deny,allow
           Allow from all
</Directory>

<Directory "/var/www/django_server/">
        AllowOverride All
        Order deny,allow
        Allow from all
</Directory>

<Location "/media/">
    SetHandler None
</Location>

<LocationMatch "\.(jpg|gif|png)$">
    SetHandler None
</LocationMatch>

Alias /static/admin/ /usr/local/lib/python2.7/site-packages/django/contrib/admin/static/admin/
Alias /static/ /var/www/django_server/static/


最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务