CMS_Django_Backend/apps/auth/views.py

45 lines
1.1 KiB
Python
Raw Normal View History

2024-08-18 20:51:27 +08:00
import json
from django.shortcuts import HttpResponse
from django.middleware.csrf import get_token
from django.views.decorators.http import require_GET, require_POST
from apps.auth import models as auth_models
# Create your views here.
@require_GET
def gettoken(request):
"""
获取token
:param request:
:return:
"""
token = get_token(request)
return HttpResponse(json.dumps({'token': token}), content_type="application/json,charset=utf-8")
@require_POST
def search_user(request):
"""
查询用户名
:param request:
:return:
"""
username = request.POST.get('username')
user = auth_models.User.objects.filter(username=username)
if user.exists():
return HttpResponse("用户名已存在")
else:
return HttpResponse(True)
@require_POST
def adduser(request):
"""
用户注册
:param request: POST提交注册信息
:return: 注册结果
先查询数据库中用户名username是否存在如果存在则提示用户更改用户名若不存在则进行存储
"""
return HttpResponse("添加用户成功")