Thanks, both techniques are working now i.e 1)Replacing User.delete(u.id) with u.delete() and in 2) user is no getting authenticated with email, it is authenticated with only username and password with authenticate function. But it is fine. On Monday, December 26, 2022 at 12:22:40 AM UTC+5:30 ength...@gmail.com wrote:
> from django.contrib.auth import authenticate > def delete_account(request): > if request.method == "POST": > email = request.POST.get('email') > password = request.POST.get('pswd1') > > u = > User.authenticate(request=request,email=email,password=password) #this will > check if any user exist with current password and email . > if u : > print(u) > u.delete() > messages.success(request,"Account is deleted > successfully.....") > > return redirect('home') > message.error(request,'incorrect user input data') > return redirect('home') > > Reply to all > Reply to the author > Forward > > > On Sunday, 25 December 2022 at 10:20:12 UTC+3 manjushak...@gmail.com > wrote: > >> def delete_account(request): >> if request.method == "POST": >> email = request.POST.get('email') >> password = request.POST.get('pswd1') >> >> u = User.objects.filter(email=email).first() >> print(u) >> User.delete(u.id) >> messages.success(request,"Account is deleted successfully.....") >> return redirect('home') >> >> return render(request,"account/delete_profile.html") >> >> >> by >> using this function i am trying to delete the user , but it shows me >> following error i.e attribute error so how can I find default id of the >> user which is already created at the time of registration, I am not using >> rest framework of django and also not created any user model in >> model.py file. [image: >> error.png] In this way I'am registering the user >> >> def register(response): >> if response.method == "POST" : >> username = response.POST["username"] >> email = response.POST["email"] >> password1 = response.POST["pswd1"] >> password2 = response.POST["pswd2"] >> >> try: >> myuser = User.objects.create_user(username, email, password1) >> myuser.password2 = password2 >> >> myuser.save() >> #if myuser.objects.filter : >> if len(username) >10: >> messages.error(response,"Username should contain at most >> 10 characters.") >> except IntegrityError: >> pass >> messages.success(response,"You have successfully registered.") >> return redirect('login') >> >> return render(response,'account/registration.html') >> >> On Sunday, December 25, 2022 at 4:44:06 AM UTC+5:30 ength...@gmail.com >> wrote: >> >>> *************************************************** >>> views.py >>> from rest_framework import generics,permissions >>> class NotifyDestroy(generics.DestroyAPIView): >>> """delete current user """ >>> permission_classes=[permissions.IsAuthenticated] >>> serializer_class=user_delete_ser >>> queryset=User.objects.all() >>> >>> ********************************************* >>> serializers.py >>> >>> from rest_framework.serializers import ModelSerializer >>> class user_setting_ser(ModelSerializer): >>> class Meta: >>> model=User >>> fields=['id'] >>> >>> >>> **************************************** >>> urls.py >>> >>> path('delete_user/<int:pk>',NotifyDestroy.as_view(),name='delete-current-user'), >>> >>> >>>> ********************************* >>> >> -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/00ffff29-29ee-4020-9b3a-b0076594fcb8n%40googlegroups.com.