<博客建立历程>阿里云建站2——Django环境准备

时间:Oct. 31, 2016 分类:

目录:

通过pip下载Django

下载pip

wget "https://pypi.python.org/packages/source/p/pip/pip-1.5.4.tar.gz#md5=834b2904f92d46aaa333267fb1c922bb"` 
 --no-check-certificate
--2016-10-20 21:18:44--  https://pypi.python.org/packages/source/p/pip/pip-1.5.4.tar.gz
Resolving pypi.python.org... 151.101.16.223, 2a04:4e42:4::223
Connecting to pypi.python.org|151.101.16.223|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1081874 (1.0M) 
[application/octet-stream]
Saving to: “pip-1.5.4.tar.gz”

100%[=====================================================================================================================================================>] 1,081,874   18.7K/s   in 34s     

2016-10-20 21:19:22 (31.5 KB/s) - “pip-1.5.4.tar.gz” saved [1081874/1081874]
[root@why ~]# ll
total 1060
-rw-r--r-- 1 root root 1081874 Jan  9  2016 pip-1.5.4.tar.gz
[root@why ~]# tar -zxvf pip-1.5.4.tar.gz 
   80  cd pip-1.5.4
   81  ll
   82  python setup.py install
   83  echo $?

如果需要以下问题

[root@why pip-1.5.4]# python setup.py install
Traceback (most recent call last):
  File "setup.py", line 6, in <module>
    from setuptools import setup, find_packages
ImportError: No module named setuptools

[root@why src]# wget https://pypi.python.org/packages/07/a0/11d3d76df54b9701c0f7bf23ea9b00c61c5e14eb7962bb29aed866a5844e/setuptools-36.2.7.zip#md5=b9e6c049617bac0f9e908a41ab4a29ac
[root@why src]# unzip setuptools-36.2.7.zip
[root@why src]# cd setuptools-36.2.7
[root@why setuptools-36.2.7]# python setup.py install
[root@why setuptools-36.2.7]# ln -s /opt/python-2.7.13/bin/pip /usr/bin/pip

指定Django1.6版本进行下载

博主因为个人对linux理解不够透彻,就没有修改Python版本,所以就用CentOS6.5版本自带的Ppython2.6.6进行学习,使用的Django版本为1.6。

[root@why pip-1.5.4]# pip install django==1.6
Downloading/unpacking django==1.6
  http://mirrors.aliyun.com/pypi/simple/django/1.6 uses an insecure transport scheme (http). Consider using https if mirrors.aliyun.com has it available
  http://mirrors.aliyun.com/pypi/simple/django/ uses an insecure transport scheme (http). Consider using https if mirrors.aliyun.com has it available
  Downloading Django-1.6-py2.py3-none-any.whl (6.7MB): 6.7MB downloaded
Installing collected packages: django
Successfully installed django
Cleaning up...

下载MySQL和Python MySQLdb库

下载MySQL

yum instal -y mysql mysql-server 
service mysql start

下载Python MySQLdb库

wget http://jaist.dl.sourceforge.net/project/mysql-python/mysql-python-test/1.2.3c1/MySQL-python-1.2.3c1.tar.gz
yum install python-devel mysql-devel zlib-devel openssl-devel  mysql-devel.x86_64
这几个库是MySQLdb的依赖库,一定要安装。
python setup.py  install

注意

以上为准备工作 使用的环境为Python2.6.6 阿里云CentOS镜像

创建Django项目

在~目录下进行的操作
这边我的规划有问题 ,并没有按着我起以前的规划来 GG 先这样吧

[root@why ~]# ll

[root@why ~]#  django-admin.py startproject mysite`
[root@why ~]# ll

[root@why ~]# cd mysite/`
[root@why mysite]# ll

添加Blog模块

[root@why mysite]# ./manage.py startapp blog`
[root@why mysite]# ll

修改数据库编码

[root@why ~]# mysql

mysql> CREATE DATABASE why DEFAULT CHARSET=utf8;
mysql> GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER, CREATE TEMPORARY TABLES, LOCK TABLES ON why.* TO 'why'@'localhost' IDENTIFIED BY 'why123456';
# 允许why用户通过why123456的密码登录
mysql> use why
mysql> status;

修改数据库编码

主要是为了后边省略一些中文导致的问题。

cp /etc/my.cnf /etc/my.cnf.old
vi /etc/my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
default-character-set=utf8
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
[root@why usr]# service mysqld restart
mysql> status;

这样准备完成~下面就是准备博客编写了.