pip install django -i https://pypi.douban.com/ django==***
pip install virtualenv
source ***/bin/activate
virtualenv 路径
初始化
STATICFILES_DIRS = [ os.path.join(BASE_DIR, 'static') ]
sys.path.insert(0,os.path.join(BASE_DIR,'***'))
DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', 'NAME': "vue_shop", "USER":"root", "PASSWORD":"root", "HOST":"127.0.0.1", "PORT":int!! "OPTIONS":{"init_command":"SET storage_engine=INNODB"} } }
语言改为中文
# 语言改为中文 LANGUAGE_CODE = 'zh-hans' # 时区改为上海 TIME_ZONE = 'Asia/Shanghai' # 数据库存储使用时间,True时间会被存为UTC的时间 USE_TZ = False
注册应用
# encoding: utf-8 from django.contrib import admin # Register your models here. # 因为同一个目录,所以可以直接.models from .models import UserProfile # 写一个管理器:命名, model+Admin class UserProfileAdmin(admin.ModelAdmin): pass # 将UserProfile注册进我们的admin中, 并为它选择管理器 admin.site.register(UserProfile,UserProfileAdmin)
模型字段
models.TextField()
models.CharField()
models.IntegerField()
models.FloatField()
models.DateField()
models.DateTimeField()
models.EmailField()
models.ForeignKey()
models.BooleanField()
models.ImageField()
字段选项
max_length=***,
null=True/False,
blank=True/False,
verbose_name="***"
choices=***
unique=True/False
default=*** | defaut=datetime.now
help_text="***"
related_name="***" #反向查询
upload_to="***" #上传文件目录
db_table="***" #指定表名
db_column="***" #指定字段名
unique_together = ("***", "***") #联合唯一
on_delete=models.CASCADE#用于外键报错
Meta
verbose_name = "***" verbose_name_plural = verbose_name
def __str__(self): return self.username