Django2

版本

python -m django --version

Creating a project

django-admin startproject

Run

python manage.py runserver
python3 manage.py runserver
python3 manage.py runserver 0:8000

Creating app

python manage.py startapp notify

Models

from django.db import models

class BaseModel(models.Model):
    created_at = models.DateTimeField(auto_now_add=True, db_index=True)
    updated_at = models.DateTimeField(auto_now=True, db_index=True)

    class Meta:
        abstract = True

###################################

class Addrs(BaseModel):
    address = models.CharField(max_length=100, unique=True)
    balance = models.BigIntegerField(default=0, help_text="余额")

    class Meta:
        db_table = "addrs"

Migrations

python manage.py makemigrations
python manage.py migrate

Console

python manage.py shell

Rollback Migrations

python manage.py showmigrations shop

  web
  [X] 0001_initial
  [X] 0002_transactions

##########
python manage.py migrate shop 0001_initial

  Operations to perform:
    Target specific migration: 0001_initial, from shop
  Running migrations:
    Rendering model states... DONE
    Unapplying shop.0002_transactions... OK

Admin

python manage.py createsuperuser

静态文件

python manage.py collectstatic


参考:

https://docs.djangoproject.com/en/2.0/intro/tutorial01/
https://zhuanlan.zhihu.com/p/32913361

你可能感兴趣的:(Django2)