luffy Project: vue front stage separation and drf item (2) based on

user module User table

Create a user module

 

Premise: In luffy virtual environment

 1 . Terminal into the apps directory from the project root directory
 >: cd luffyapi & cd apps

 2 create App.
 >: Python ../../manage.py startapp the User

 

In pycharm terminal created, switch to the specified file directory apps.

Create a User table corresponding model: user / models.py

from django.db import models
from django.contrib.auth.models import AbstractUser
class User(AbstractUser):
    mobile = models.CharField(max_length=11, unique=True)
    icon = models.ImageField(upload_to='icon', default='icon/default.png')

    class Meta:
        db_table = 'luffy_user'
        verbose_name = '用户表'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.username

 

Registered user module configured to the User table: dev.py

INSTALLED_APPS = [
    # ...
    'user',
]

# 自定义User表
AUTH_USER_MODEL = 'user.User'

 

Configuring media

dev.py

MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')

media directory configuration

"""
├── luffyapi
    └──    luffyapi/
           └──    media/      
            └──    icon 
                └── default.png
"""

 

Main route: luffyapi / urls.py

from django.contrib import admin
from django.urls import path, re_path, include
from django.views.static import serve
from django.conf import settings
urlpatterns = [
    path('admin/', admin.site.urls),

    path('user/', include('user.urls')),

    re_path('^media/(?P<path>.*)', serve, {'document_root': settings.MEDIA_ROOT})
]

 

Sub routes: user / urls.py

from django.urls import path, re_path
urlpatterns = [

]

 

Guess you like

Origin www.cnblogs.com/Gaimo/p/11746013.html