17👍
You should change your code to:
@staff_member_required
def del_user(request, username):
try:
u = User.objects.get(username = username)
u.delete()
messages.success(request, "The user is deleted")
except User.DoesNotExist:
messages.error(request, "User doesnot exist")
return render(request, 'front.html')
except Exception as e:
return render(request, 'front.html',{'err':e.message})
return render(request, 'front.html')
and display the err
in your template to see further error messages
-5👍
@login_required
def del_user(request):
user = request.user
user.delete()
redirect("login")
- Dynamic database tables in django
- How to add a default array of values to ArrayField?
- Sending CSRF Tokens via Postman
- Django transaction management
- How to configure Apache to run ASGI in Django Channels? Is Apache even required?
Source:stackexchange.com