一起学Django之Day01

  1. 创建项目
    SimilarFacedeMacBook-Pro:PycharmProjects similarface$ django-admin startproject StudyDjango
  2. 创建App
    SimilarFacedeMacBook-Pro:PycharmProjects similarface$ cd StudyDjango/
    SimilarFacedeMacBook-Pro:StudyDjango similarface$ django-admin startapp myblog
  3. 项目结构
    SimilarFacedeMacBook-Pro:StudyDjango similarface$ tree ./
    ./
    ├── StudyDjango
    │   ├── __init__.py
    │   ├── settings.py #配置文件 
    │   ├── urls.py #路由文件
    │   └── wsgi.py
    ├── manage.py   这个文件时django-admin的功能文件不需要修改
    └── myblog
        ├── __init__.py
        ├── admin.py #django 后台admin
        ├── apps.py
        ├── migrations #ORM 的中间文件
        │   └── __init__.py
        ├── models.py #模型 实体类
        ├── tests.py 
        └── views.py  #试图文件 
    

     

  4. 生成后台数据表
    now you need create database:

    mysql> create database studydjango CHARACTER set = utf8;
    Query OK, 1 row affected (0.00 sec)

    update settings.py

    # DATABASES = {
    #     'default': {
    #         'ENGINE': 'django.db.backends.sqlite3',
    #         'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    #     }
    # }
    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.mysql',
            'NAME': 'studydjango',
            'USER': 'root',
            'PASSWORD': '123456',
            'HOST': '127.0.0.1',
            'PORT': '3306',
        }
    }
    

      

    SimilarFacedeMacBook-Pro:StudyDjango similarface$ python manage.py migrate
    /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pytz/__init__.py:29: UserWarning: Module email was already imported from /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/email/__init__.pyc, but /Library/Python/2.7/site-packages is being added to sys.path
      from pkg_resources import resource_stream
    Operations to perform:
      Apply all migrations: admin, contenttypes, auth, sessions
    Running migrations:
      Rendering model states... DONE
      Applying contenttypes.0001_initial... OK
      Applying auth.0001_initial... OK
      Applying admin.0001_initial... OK
      Applying admin.0002_logentry_remove_auto_add... OK
      Applying contenttypes.0002_remove_content_type_name... OK
      Applying auth.0002_alter_permission_name_max_length... OK
      Applying auth.0003_alter_user_email_max_length... OK
      Applying auth.0004_alter_user_username_opts... OK
      Applying auth.0005_alter_user_last_login_null... OK
      Applying auth.0006_require_contenttypes_0002... OK
      Applying auth.0007_alter_validators_add_error_messages... OK
      Applying sessions.0001_initial... OK
    
    mysql> use studydjango
    Reading table information for completion of table and column names
    You can turn off this feature to get a quicker startup with -A
    
    Database changed
    mysql> show tables;
    +----------------------------+
    | Tables_in_studydjango      |
    +----------------------------+
    | auth_group                 |
    | auth_group_permissions     |
    | auth_permission            |
    | auth_user                  |
    | auth_user_groups           |
    | auth_user_user_permissions |
    | django_admin_log           |
    | django_content_type        |
    | django_migrations          |
    | django_session             |
    +----------------------------+
    10 rows in set (0.00 sec)
  5.   

posted @ 2016-04-18 16:16  similarface  阅读(236)  评论(0编辑  收藏  举报