from django.shortcuts import render, redirect
from django.db import transaction
from .models import User
from .forms import RegisterForm, LoginForm, CheckPasswordForm
from .decorators import login_required
from django.views.decorators.http import require_POST
@require_POST
def profile_delete(request):
if request.method == 'POST':
request.user.delete()
return redirect('users:login')
return render(request, 'users/delete.html')
用户视图raise NotImplementedError("Django doesn't provide a DB representation for AnonymousUser.")
NotImplementedError: Django doesn't provide a DB representation for AnonymousUser.
我试图在django中删除用户信息,但我得到一个错误,如标题。我该怎么办?我还尝试了设置中的@login_require方法和middle_classes,但错误没有解决。
@qwe -我不认为这个请求。User是一个有效的用户。错误显示匿名用户,如果请求。用户未登录。您还应该始终添加@login_required装饰器。这将确保您需要始终登录才能访问此端点。