• python django 新增app


    ./manage.py startapp form
    
    node2:/django/mysite#tree form
    form
    ├── admin.py
    ├── admin.pyc
    ├── apps.py
    ├── __init__.py
    ├── __init__.pyc
    ├── migrations
    │   ├── __init__.py
    │   └── __init__.pyc
    ├── models.py
    ├── models.pyc
    ├── settings.py
    ├── tests.py
    └── views.py
    
    1 directory, 12 files
    
    node2:/django/mysite#cat mysite/settings.py
    
    添加类:
    INSTALLED_APPS = [
        'django.contrib.admin',
        'django.contrib.auth',
        'django.contrib.contenttypes',
        'django.contrib.sessions',
        'django.contrib.messages',
        'django.contrib.staticfiles',
        'blog',
        'form',
    ]
    
    
    node2:/django/mysite#cat form/models.py
    from django.db import models
    class Test(models.Model):
     name = models.CharField(max_length=20)
    
    
    node2:/django/mysite#./manage.py makemigrations form
    aaaaaaaaaaaaaaaa
    Migrations for 'form':
      form/migrations/0001_initial.py
        - Create model Test
    node2:/django/mysite#./manage.py migrate 
    aaaaaaaaaaaaaaaa
    Operations to perform:
      Apply all migrations: admin, auth, blog, contenttypes, form, sessions
    Running migrations:
      Applying form.0001_initial... OK
    node2:/django/mysite#
    
    
    node2:/django/mysite/form#cat migrations/0001_initial.py
    # -*- coding: utf-8 -*-
    # Generated by Django 1.11 on 2017-11-15 19:37
    from __future__ import unicode_literals
    
    from django.db import migrations, models
    
    
    class Migration(migrations.Migration):
    
        initial = True
    
        dependencies = [
        ]
    
        operations = [
            migrations.CreateModel(
                name='Test',
                fields=[
                    ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                    ('name', models.CharField(max_length=20)),
                ],
            ),
        ]
    
    mysql> show tables;
    +----------------------------+
    | Tables_in_tlcb             |
    +----------------------------+
    | auth_group                 |
    | auth_group_permissions     |
    | auth_permission            |
    | auth_user                  |
    | auth_user_groups           |
    | auth_user_user_permissions |
    | blog_blogpost              |
    | blog_book                  |
    | django_admin_log           |
    | django_content_type        |
    | django_migrations          |
    | django_session             |
    | form_test                  |
    +----------------------------+
    13 rows in set (0.00 sec)

  • 相关阅读:
    弹出层
    jQuerySelectors(选择器)的使用(三、简单篇)
    jQuerySelectors(选择器)的使用(二、层次篇)
    jQuerySelectors(选择器)的使用(四五、内容篇&可见性篇)
    对frameset、frame、iframe的js操作
    文件上传
    C# 字符串操作
    图片防盗链之HttpHandler方法实现
    MSSQL 存储过程
    dataset操作
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13349421.html
Copyright © 2020-2023  润新知