版本号为2.7.6
所以不用安装了
?
2 安装Django,最新的版本1.7
(1)首先使用easy_install安装pip(easy_install是Python的包管理工具,类似Ruby下的gem,pip是升级版的easy_install), sudo easy_install pip
(2)安装成功后,安装Django, pip install Django==1.7
(3)查看安装路径:默认为/usr/bin,如果看到django-admin.py说明安装成功,django-admin.py是Django的管理工具,用来生成项目和应用
?
3 连接mysql
(1)安装mysql for mac,直接从官网上下载dmg文件安装即可,需要64位版本
(2)安装mysql python驱动, sudo easy_install mysql-python
?
4 创建第一个项目
(2)创建应用:
cd demoproject
创建成功
(3)修改settting.py,将demoapp加入到INSTALLED_APPS
INSTALLED_APPS = (
??? ‘django.contrib.admin‘,
??? ‘django.contrib.auth‘,
??? ‘django.contrib.contenttypes‘,
??? ‘django.contrib.sessions‘,
??? ‘django.contrib.messages‘,
??? ‘django.contrib.staticfiles‘,
??? ‘demoapp‘
)
(4)修改settting.py,将默认的sqlite数据库换成mysql
DATABASES = {
??? ‘default‘: {
??????? ‘ENGINE‘: ‘django.db.backends.mysql‘,
??????? ‘NAME‘: ‘djangodb‘,
??????? ‘USER‘: ‘root‘,
??????? ‘PASSWORD‘: ‘root‘,
??????? ‘HOST‘: ‘127.0.0.1‘,
??????? ‘PORT‘: ‘3306‘,??????????????????
??? }
}
(5)在demoproject下输入:python
manage.py dbshell,如果能正常进入mysql命令行,则说明连接成功
Welcome to the MySQL monitor.? Commands end with ; or \g.
Your MySQL connection id is 270
Server version: 5.5.38 MySQL Community Server (GPL)
?
Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
?
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
?
Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.
?
Operations to perform:
? Apply all migrations: admin, contenttypes, auth, sessions
Running migrations:
? Applying contenttypes.0001_initial... OK
? Applying auth.0001_initial... OK
? Applying admin.0001_initial... OK
? Applying sessions.0001_initial... OK
?
You have installed Django‘s auth system, and don‘t have any superusers defined.
Would you like to create one now? (yes/no): yes
Username (leave blank to use ‘thierry‘): thierry
Password:
Password (again):