一、思路:发起登陆请求,响应登陆页面,输入密码,响应登陆成功,进入个人中心。
二、步骤:models.py—>迁移同步—>views.py—>templates.html文件—>urls—>程序运行—>测试
三、详细流程走一下:
1.modele.py:
from django.db import models
# Create your models here.
class Person(models.Model):
yourname = models.CharField(max_length=32,unique=True,null=False)
yourpassword = models.CharField(max_length=256,null=False)
2.连接数据库,迁移同步
python manage.py makemigrations
python manage.py migrate
3.views.py:
from django.http import HttpResponse
from django.shortcuts import render, redirect
# Create your views here.
from django.views.generic import TemplateView
from APP.models import Person
#用户登陆
def login(request):
if request.method == 'GET':
return render(request,'login.html')
elif request.method == 'POST':
username = request.POST.get('username')
password = request.POST.get('password')
persons = Person.objects.filter(yourname=username)
#判断名字是否存在1
if not persons.exists():
return HttpResponse('用户名不存在'