国际化配置
LANGUAGE_CODE = 'zh-hans' TIME_ZONE = 'Asia/Shanghai' USE_I18N = True USE_L10N = True USE_TZ = False
自定义User表
models.py
class User(AbstractUser): mobile = models.BigIntegerField(unique=True,null=True) def __str__(self): return self.username
settings.py
AUTH_USER_MODEL = 'api.USer'
admin.py
from django.contrib import admin from . import models from django.contrib.auth.admin import UserAdmin as DjangoUserAdmin # 自定义User表后,admin界面管理User类 class UserAdmin(DjangoUserAdmin): # 添加用户课操作字段 add_fieldsets = ( (None, { 'classes': ('wide',), 'fields': ('username', 'password1', 'password2', 'is_staff', 'mobile', 'groups', 'user_permissions'), }), ) # 展示用户呈现的字段 list_display = ('username', 'mobile', 'is_staff', 'is_active', 'is_superuser') admin.site.register(models.User, UserAdmin) admin.site.register(models.Book) admin.site.register(models.Car)
pip换源
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
MEDIA相关配置
urls.py
from django.views.static import serve urlpatterns = [ url(r'^media/(?P<path>.*)', serve, {"document_root": settings.MEDIA_ROOT}) ]
settings.py
MEDIA_URL = '/media/' MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
数据库相关配置
settings.py
import pymysql pymysql.install_as_MySQLdb() DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', 'NAME': 'day72', 'USER': 'root', 'PASSWORD': '', 'HOST':'127.0.0.1', 'PORT':3306 } }
来源:https://www.cnblogs.com/Ghostant/p/12363246.html