python3.7+django 学习笔记2

1.在app/models建立一个moment定义信息发布表

from django.db import models

# Create your models here.

class Moment(models.Model):
    content=models.CharField(max_length=300)
    user_name = models.CharField(max_length=20)


    kind = models.CharField(max_length=20)

分别执行下面

python manage.py makemigrations app

修改了一下content的长度 200=300

再次执行

python manage.py makemigrations app

执行python manage.py migrate 移植到数据库

 

appledeMacBook-Pro-3:py3DjangoSite apple$ python manage.py makemigrations app
Migrations for 'app':
  app/migrations/0001_initial.py
    - Create model Moment
appledeMacBook-Pro-3:py3DjangoSite apple$ python manage.py makemigrations app
Migrations for 'app':
  app/migrations/0002_auto_20191223_0716.py
    - Alter field content on moment
appledeMacBook-Pro-3:py3DjangoSite apple$ python manage.py migrate
Operations to perform:
  Apply all migrations: admin, app, auth, contenttypes, sessions
Running migrations:
  Applying contenttypes.0001_initial... OK
  Applying auth.0001_initial... OK
  Applying admin.0001_initial... OK
  Applying admin.0002_logentry_remove_auto_add... OK
  Applying admin.0003_logentry_add_action_flag_choices... OK
  Applying app.0001_initial... OK
  Applying app.0002_auto_20191223_0716... 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 auth.0008_alter_user_username_max_length... OK
  Applying auth.0009_alter_user_last_name_max_length... OK
  Applying auth.0010_alter_group_name_max_length... OK
  Applying auth.0011_update_proxy_permissions... OK
  Applying sessions.0001_initial... OK

python3.7+django 学习笔记2

修改了models需要执行

appledeMacBook-Pro-3:py3DjangoSite apple$

python manage.py makemigrations app
Migrations for 'app':
  app/migrations/0003_auto_20191223_0731.py
    - Alter field kind on moment
    - Alter field user_name on moment
appledeMacBook-Pro-3:py3DjangoSite apple$ python manage.py migrate
Operations to perform:
  Apply all migrations: admin, app, auth, contenttypes, sessions
Running migrations:
  Applying app.0003_auto_20191223_0731... OK
 

2.建立一个template页面

python3.7+django 学习笔记2

输入提交后,提示这个

python3.7+django 学习笔记2

关闭setting.py里面的

python3.7+django 学习笔记2

页面需要增加一个:html中的form添加模板标签{% csrf_token %}配置就可以通过

 

3.增加管理页面

python manage.py createsuperuser
 

python3.7+django 学习笔记2