如果出现
EnvironmentError: mysql_config not found
应该:- You installed python
- You did
brew install mysql
- You did
export PATH=$PATH:/usr/local/mysql/bin
- And finally, you did
pip install MySQL-Python
4 创建第一个项目(1)创建项目:django-admin.py startproject demoproject(2)创建应用:cd demoprojectpython manage.py startapp demoapp创建成功(3)修改settting.py,将demoapp加入到INSTALLED_APPSINSTALLED_APPS = ( 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'demoapp')(4)修改settting.py,将默认的sqlite数据库换成mysqlDATABASES = { '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 270Server 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 itsaffiliates. Other names may be trademarks of their respectiveowners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> 5 启动应用(1)同步数据库:执行python manage.py syncdb,第一次启动需要创建superuser,用来管理django后台Operations to perform: Apply all migrations: admin, contenttypes, auth, sessionsRunning 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): yesUsername (leave blank to use 'thierry'): thierryEmail address: thierry.xing@gmail.comPassword: Password (again): Superuser created successfully. (2)启动服务:python manage.py runserver:Performing system checks... System check identified no issues (0 silenced).December 03, 2014 - 08:36:46Django version 1.7, using settings 'djproject.settings'Starting development server at http://127.0.0.1:8000/Quit the server with CONTROL-C. 启动成功,在浏览器输入http://127.0.0.1:8000/打开应用在浏览器输入http://127.0.0.1:8000/admin进入后台管理应用