17👍
You should show the code that didn’t work. From your description though, you’re doing a few things wrong.
First, .filter()
always returns a queryset, not an instance. To get an instance, you should use .get()
.
Secondly, User
is the class; the instance is user
.
Thirdly, you have no reason to do a query here at all. request.user
is already the User instance. There is no need to take that user, get its profile, ask the profile for the user ID, then do another query to get back the user you started with. Just use the user you already have.
Finally, never, ever do a blank except
, as that will catch all sorts of unexpected errors and hide anything that could be going wrong. Only catch exceptions you actually know how to deal with. In this case, there is nothing specific you need to handle; if anything unexpected goes wrong, let Django report that error normally.
def delete_profile(request):
user = request.user
user.is_active = False
user.save()
messages.success(request, 'Profile successfully disabled.')
return redirect('index')
3👍
You may need to set user.is_active = False
and then save the user
object.
def delete_profile(request):
user = request.user
user.is_active = False
user.save()
logout(request)
messages.success(request, 'Profile successfully disabled.')
return redirect('index')
- [Django]-Authenticating Android with firebase Authentication and send token to verify to backend Django
- [Django]-Django: Related model 'users.UserProfile' cannot be resolved
- [Django]-Django: How is a RelatedManager object instantiated?
- [Django]-Django-allauth adapter redirects
- [Django]-What's your favorite way to test the javascript in your djangoapp?
- [Django]-Command not found: django-admin (using anaconda 3.2.4 and pyenv)
- [Django]-JSON Response from Django in Android
- [Django]-Exception while installing packages in Python
0👍
After calling user.is_active = False
you need to write the changes to the database by calling user.save()
- [Django]-How to pass args to a signal
- [Django]-Passing Editable Fields as validated_data method of Django-Rest-Framework Serializer
- [Django]-Redirect realtime common line output to Django HttpResponse
- [Django]-Using Django with MySQL for storing and looking up Large DNA Microarray Results
- [Django]-How to use python-social-auth with google only?