zoukankan      html  css  js  c++  java
  • django、drf相关配置

    国际化配置

    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
        }
    }
    
  • 相关阅读:
    关于值传递和引用传递
    单例设计模式(创建型模式)
    逻辑分页和物理分页
    java基本数据类型
    Keepalived笔记
    lvs,HAProxy,nginx简单笔记
    限流, 熔断,降级笔记
    redis事务之watch
    Redis-Sentinel
    正式入驻博客园
  • 原文地址:https://www.cnblogs.com/Ghostant/p/12363246.html
Copyright © 2011-2022 走看看