itsdangerous加密:
在开发过程中会遇到一些需要用户激活使用的链接
这些需要带有用户的相关信息
又不希望这些信息以明文的方式展现给用户
防止不放分子从中作恶
这时就可以使用itsdangerous来对数据进行加密
之后再对加密的数据进行解密得到用户信息
从而对该用户进行激活认证
views.py中实现登录以及注册功能
from django.shortcuts import render
from django.views import View
from django.http import HttpResponse
from itsdangerous import TimedJSONWebSignatureSerializer as SE
from itsdangerous import SignatureExpired
from TY.settings import SECRET_KEY
import time
from .models import Users
class RegisterResponse(View):
def get(self,request):
return render(request,"zuoye/register.html")
def post(self,request):
username = request.POST.get("username")
password = request.POST.get("password")
if not (username and password):
return HttpResponse("用户名以及密码不能为空")
Serializer = SE(SECRET_KEY, 60000)
info = {
username:password}
ret = Serializer.dumps(info)