In Mac 10.10, how does one set up the Python2.7 + Django1.7 + MySQL5.5 environment?

Source: Internet
Author: User
Tags auth sessions sqlite database install django mysql command line pip install django

1 Mac system comes with Python by default. View the version:
Command line input: python
Python 2.7.6 (default, Sep 9 2014, 15:04:36)
Version 2.7.6
So you don't need to install
 
2. Install Django. The latest version is 1.7.
(1) first install pip using easy_install (easy_install is a Python package management tool, similar to the gem in Ruby, pip is an upgraded version of easy_install), sudo easy_install pip
(2) after successful installation, install Django, pip install Django = 1.7
(3) view the installation path: the default is/usr/bin, if you see the django-admin.py that the installation is successful, the django-admin.py is the Django management tool, used to generate projects and applications
 
3. Connect to mysql
(1) install mysql for mac and download the dmg file from the official website. The 64-bit version is required.
(2) install the mysql python driver and sudo easy_install mysql-python
 
4. Create the first project
(1) create project: django-admin.py startproject demoproject
(2) create an application:
Cd demoproject
Python manage. py startapp demoapp
Created successfully
(3) modify setmedia. py and add demoapp to INSTALLED_APPS.

INSTALLED_APPS = (
'Django. contrib. Admin ',
'Django. contrib. Auth ',
'Django. contrib. contenttypes ',
'Django. contrib. Session ',
'Django. contrib. messages ',
'Django. contrib. Staticfiles ',
'Demoapp'
)

(4) modify setbench. py and replace the default sqlite database with mysql.

DATABASES = {
'Default ':{
'Engine': 'Django. db. backends. Mysql ',
'Name': 'djangdb ',
'User': 'root ',
'Password': 'root ',
'Host': '2017. 0.0.1 ',
'Port': '123 ',
    }
}

(5) enter python manage. py dbshell in demoproject. If you can access the mysql command line normally, the connection is successful.
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,201 4, 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. Start the application
(1) synchronize the database: execute python manage. py syncdb and create a superuser to manage the django background at the first startup.
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.
Wocould 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) start the service: python manage. py runserver:
Padding system checks...
 
System check identified no issues (0 silenced ).
December 03,201 4-08:36:46
Django version 1.7, using settings 'djproject. Setting'
Starting development server at http: // 127.0.0.1: 8000/
Quit the server with CONTROL-C.
 
Started successfully. Enter http: // 127.0.0.1: 8000 in the browser to open the application.
Enter http: // 127.0.0.1: 8000/admin in the browser to enter the background management application.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.