Mac 10.10下Python2.7+Django1.7+MySQL5.5环境搭建
来源:互联网 发布:apache logo 编辑:程序博客网 时间:2024/05/17 08:43
1 Mac系统默认自带Python,查看版本:
命令行输入:python
Python 2.7.6 (default, Sep 9 2014, 15:04:36)
版本号为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
如果出现
如果出现
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 demoproject
python manage.py startapp demoapp
创建成功
(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.
mysql>
5 启动应用
(1)同步数据库:执行python manage.py syncdb,第一次启动需要创建superuser,用来管理django后台
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
Email address: thierry.xing@gmail.com
Password:
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:46
Django 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进入后台管理应用
0 0
- Mac 10.10下Python2.7+Django1.7+MySQL5.5环境搭建
- Python2.6+Django1.4+Mysql5.5+eclipse的环境搭建
- python34+Django1.7+mysql5.5环境搭建(win7)
- Django 环境搭建(CentOS65 + Django1.7 + mySQL5.1)
- django1.7.4+python2.7.6 +mysql5.5 搭建一个工程实例
- Mac下selenium3.0+python2.7环境搭建
- Linux下搭建Python2.7环境
- Python2.7 Django1.8 CentOS7 Apache2.4 mod_wsgi4.4.21 环境下部署
- Debian+Django1.11+Apache2.4+mod_wsgi+python2.7搭建服务器
- Fedora22环境下Python3.4+Django1.8+MySQL5.6环境搭建
- Django1.3.1 with python2.5 环境配置
- 在centos6.5环境下搭建多版本python(python2.6、python2.7、python3.5)共存环境
- Windows下python2.7+opencv环境的搭建
- 64位win&python2.7下gensim环境搭建
- 64位win&python2.7下gensim环境搭建
- tomcat7+mysql5.5+jdk1.7环境搭建
- 安装Django python2.7 + Django1.5.12
- 快速使用Python2.7和Django1.9
- A+B Problem 高精度
- HDU 3078 — Network
- 统计起始日期之间有多少个2月29日
- struts2自定义拦截器注解配置方法
- sql
- Mac 10.10下Python2.7+Django1.7+MySQL5.5环境搭建
- 配置元数据
- 时间函数---转换成指定格式的时间函数
- 第三章第九题
- 从今天开始学习JavaSE-JDK平台的安装
- jstl变量作用域控制 scope
- hdu 3344 Kakuro Extension Extension
- 一把干3类
- HDU3622.Bomb Game——2-sat二分最大值+可行性判定