// 1. 创建虚拟环境 python -m venv xxx (虚拟环境的名字)
// 2. 开启虚拟环境 scrips 下 执行 activate.bat 退出deactivate.bat
// 2. 查看已经安装的三方库 pip freeze
// 3. django-admin startproject xxx (项目名称)
// 4. cd 到 项目里 python manage.py runserver
1.安装 python
1.1 查看本地是否安装
直接官网下载
https://www.python.org/getit/
python -V (注意是 大写的V,小写的是不对的)
python --version (注意 有两个--)
下图是两个都安装好了

2.安装 jdango
2.1 安装 pip
mac 中自带 easy_install,所有直接在 终端里面输入 sudo easy_install pip

2.2 安装 jdango
pip install jdango

查看 Django 版本
python -m django --version
3 Django 创建 第一个应用
3.1 在所在目录 执行命令
django-admin.py startproject HelloWorld // 即可得到 第一个Django项目
3.2 启动服务
python manage.py runserver 0.0.0.0:8000
链接成功页面

4 视图和 URL 的配置
4.1 新增 view.py 页面,内容如下
from django.http import HttpResponse
def hello(request):
return HttpResponse("Hello world ! this is forst page form Django")
4.2 修改 settings.py 的内容
from django.conf.urls import url
from . import view
urlpatterns = [
url(r'^$', view.hello),
]
结果如下

5 Django 模板
template 的使用 (更多几处修改请移步git)
# -*- coding: utf-8 -*-
#from django.http import HttpResponse
from django.shortcuts import render
def hello(request):
context = {}
context['hello'] = 'Hello World!'
return render(request, 'hello.html', context)

6 mac 中数据库的安装
http://blog.csdn.net/rebirth_love/article/details/72854306
6.1 下载
https://dev.mysql.com/downloads/mysql/
安装好了 会给个默认密码

6.2
在偏好设置 下面,点击启动


6.3 用 命令行登陆
/usr/local/mysql/bin/mysql -u root -p
输入密码:
6.4 成功

tops:遇到的问题:
如遇到 找不到 mysql 命令
执行 sudo ln -s /usr/local/mysql/bin/mysql /usr/bin
若遇到
mysql Operation not permitted
执行
sudo ln -s /usr/local/mysql/bin/mysql /usr/local/bin
链接:http://www.cnblogs.com/0201zcr/p/6649302.html
若需要卸载
http://www.jb51.net/article/81447.htm //卸载
网友评论