网址:https://adminlte.io
https://adminlte.io/themes/AdminLTE/index2.html
使用:AdminLTE 2.4.3
1.templates>cms>login---复制源代码,
2.创建front>dist>adminlte/(bower_components)相关文件复制进去
{%static ' adminlte'%}
3.修改app》view.py2
from django.shortcuts import render
# Create your views here.
def login_view(request):
return render(request,'cms/login.html')
创建app》cms>urls
from django .urls import path
from . import views
app_name ='cms'
urlpatterns=[
path('login/',views.login_view,name='login')
]
4,修改总urls
path('cms/',include("apps.cms.urls")),
5,修改页面显示!templates》cms》login.html
如此套路实例:登录
http://127.0.0.1:8000/cms/login/
--------------------------user模型创建------------
编写登录逻辑:
1,【存放模型】创建app>>xfzautl>models.py
【安装pip】:
pip install django-shortuuidfield
【models内容】:
from django.contrib.auth.models import AbstractBaseUser,PermissionsMixin,BaseUserManager
from shortuuidfield import ShortUUIDField
from django.db import models
class UserManager(BaseUserManager):
def _create_user(self,telephone,username,password,**kwargs):
if not telephone:
raise ValueError('请传入手机号码!')
if not username:
raise ValueError('请传入用户名!')
if not password:
raise ValueError('请传入密码!')
user = self.model(telephone=telephone,username=username,**kwargs)
user.set_password(password)
user.save()
return user
def create_user(self,telephone,username,password,**kwargs):
kwargs['is_superuser'] = False
return self._create_user(telephone,username,password,**kwargs)
def create_superuser(self,telephone,username,password,**kwargs):
kwargs['is_superuser'] = True
kwargs['is_staff'] = True
return self._create_user(telephone,username,password,**kwargs)
class User(AbstractBaseUser,PermissionsMixin):
# 我们不使用默认的自增长的主键
# id:100,101,102,103
# uuid/shortuuid
# Shortuuidfield:pip install django-shortuuidfield
uid = ShortUUIDField(primary_key=True)
telephone = models.CharField(max_length=11,unique=True)
email = models.EmailField(unique=True,null=True)
username = models.CharField(max_length=100)
is_active = models.BooleanField(default=True)
is_staff = models.BooleanField(default=False)
data_joined = models.DateTimeField(auto_now_add=True)
USERNAME_FIELD = 'telephone'
# telephone,username,password
REQUIRED_FIELDS = ['username']
EMAIL_FIELD = 'email'
objects = UserManager()
def get_full_name(self):
return self.username
def get_short_name(self):
return self.username
【settings修改】
app:
'apps.xfz1autl',
AUTH_USER_MODEL = 'xfz1autl.User'
【迁移数据库】:
生成迁移: python manage.py makemigrations
执行迁移: python manage.py migrate