This may sounds a stupid question but I have difficulty deleting users in django using this view:
@staff_member_required
def del_user(request, username):
try:
u = User.objects.get(username = username)
u.delete()
messages.sucess(request, "The user is deleted")
except:
messages.error(request, "The user not found")
return render(request, 'front.html')
in urls.py I have
url(r'^del_user/(?P<username>[\w|\W.-]+)/$', 'profile.views.del_user'),
Instead the user being deleted I get The user not found
.
What can be wrong here?
try: yourcode... expect DoesNotExist: dosomething...
instead. – Vicenta