Mac Python+Django+MySql 环境搭建

Mac系统天生自带就有Python,这一点儿我感觉比windows 要方便许多,本文主要说一下Mac下的环境安装和配置。
1 . 来看一下电脑中安装的Python的版本

localhost:~ wany$ python -V 
Python 2.7.10

2 . 安装Django。 Python的包管理工具默认是easy_install,在安装Python 的时候,系统已经装好了。pip是现在比较流行的一个Python包管理工具,功能肯定也要比easy_install强大许多,故我们使用easy_install来安装pip,然后使用pip来安装django框架,我这里安装的是django的1.7版本

localhost:~ wany$ sudo easy_install pip
localhost:~ wany$ pip install Django==1.7

3 . 安装mysql, 使用HomeBrew 进行安装,如果没有电脑中没有安装可以点这里安装。

localhost:~ wany$ sudo brew install mysql

3 . 创建第一个项目

1)创建项目:

localhost:~ wany$ django-admin startproject demoproject

2)创建应用:

localhost:~ wany$ cd demoproject
localhost:demoproject wany$ python manage.py startapp demoapp

创建成功
3)修改settting.py,将demoapp加入到INSTALLED_APPS

localhost:demoproject wany$ cd demoproject
localhost:demoproject wany$ sudo vim settings.py

修改INSTALLED_APPS如下

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'demoapp'
)

4)启动项目

localhost:~ wany$ cd demoproject
localhost:demoproject wany$ python manage.py runserver
Performing system checks...

System check identified no issues (0 silenced).

You have unapplied migrations; your app may not work properly until they are applied.
Run 'python manage.py migrate' to apply them.

September 09, 2016 - 06:42:31
Django version 1.9.6, using settings 'demoproject.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.

  1. 浏览器 访问 http://127.0.0.1:8000/
    页面显示 ‘it works’ 字样
    至此,安装已经完成了

你可能感兴趣的:(Mac Python+Django+MySql 环境搭建)