Install Django

=========第一次装倒是可以的==================

https://docs.djangoproject.com/en/1.10/intro/tutorial01/
http://www.aichengxu.com/view/42213

1.first install python


2.install Django

pip install Django==1.10.4
======
python
>>> import django
>>> print(django.get_version())
1.10.4
=====or======
python -m django --version
1.10.4
======

3.create a project
$ django-admin startproject mysite

//此时出现一些问题,说明还是没有安装好django,解决方法是:
建立虚拟环境,在虚拟环境下安装django,

at this point,there are some problems that django is not installed successfully,slove as follows:
1.install virtual environment
2.install django in a virtual environment


4.install virtualenv(creat a virtual env)
$ pip install virtualenv
$ virtualenv --version
$ virtualenv venv
$ source venv/bin/activate
$ deactivate //jump out of the virtual env

5.此时执行
pip install django
django-admin.py --help //mean the installation is successful
现在可以敲写这行命令来建一个project了:
now you can type the command line for creating a project
$ django-admin startproject mysite

=========第二次装倒是不可以的=====改进=============

https://docs.djangoproject.com/en/1.10/intro/tutorial01/
http://www.aichengxu.com/view/42213

1.first install python

升级python http://www.2cto.com/kf/201603/493564.html

wget https://www.python.org/ftp/python/3.4.4/Python-3.4.4.tgz
tar -zxvf Python-3.4.4.tgz

进行编译安装
cd Python-3.4.4
sudo mkdir /usr/local/python3.4.4
./configure --prefix=/usr/local/python3.4.4
make
sudo make install

#备份python旧版本信息
sudo mv /usr/bin/python /usr/bin/python2.6_old
#删除旧链接并重新创建链接
sudo rm /usr/bin/python2
sudo ln -s /usr/bin/python2.6_old /usr/bin/python2

#重新建立Python3.4的环境变量
sudo ln -s /usr/local/python3.4.4/bin/python3.4 /usr/bin/python

1.2 pip 也要跟着改变

http://www.cnblogs.com/wenchengxiaopenyou/p/5709218.html


2.install Django

sudo pip install Django==1.10.4

======
python
>>> import django
>>> print(django.get_version())
1.10.4
=====or======
python -m django --version
1.10.4
======

3.create a project
$ django-admin startproject mysite

//此时出现一些问题,说明还是没有安装好django,解决方法是:
建立虚拟环境,在虚拟环境下安装django,

at this point,there are some problems that django is not installed successfully,slove as follows:
1.install virtual environment
2.install django in a virtual environment


4.install virtualenv(creat a virtual env)
$ sudo pip install virtualenv
$ virtualenv --version
$ virtualenv venv
$ source venv/bin/activate
$ deactivate //jump out of the virtual env

5.此时执行
pip install django
django-admin.py --help //mean the installation is successful
现在可以敲写这行命令来建一个project了:
now you can type the command line for creating a project
$ django-admin startproject mysite

6.创建数据库
mysql -uroot -prysly
create database testDb character set utf8 collate utf8_unicode_ci;
show databases;
use testDb
show tables;

删除数据库
drop database testDb;

创建表:创建了一个只有自增id字段的username表
create table username(id int not null primary key auto_increment);

删除表
drop table username;

添加表字段
alter table username add citycode varchar(6) not null default 0;

删除表字段
ALTER TABLE username DROP citycode;

查看数据表有哪些字段
desc username;
show create table username;

修改表名称
rename table username to user;

修改表字段名称
alter table user modify new1 varchar(10);  //修改一个字段的类型
alter table user change new1 new4 int;  //修改一个字段的名称,此时一定要重新指定该字段的类型
alter table city modify city varchar(8) not null default '上海';
如果要删除一些属性: 在这里指定id的新类型为int,其他的如自增,自然是删掉了,但是主键没有删除掉。
alter table user modify id int;

设置id 自增
alter table city change id id int auto_increment;
alter table city modify id int auto_increment;

表插入数据
insert into city values (1, 'dd', '333ff', '', '');

表删除数据
delete from city where id=1;
delete from city where id in ('2', '3');


删除主键
alter table user modify id int; //先删除自增长
alter table user drop primary key; //再删除主键

添加主键
alter table user add primary key(id);
alter table user change id id int(10) not null auto_increment;

update user set tel=11111111111 where id=2;


select * from user;
select mail from user where id=3;

原文地址:https://www.cnblogs.com/rysly/p/django.html