Views.py
class ProfileCreate(LoginRequiredMixin, UserPassesTestMixin, UpdateView):
model = User
form_class = ProfileForm
template_name = "profile/profile_new.html"
slug_field = "username"
def get_login_url(self):
return reverse('account_login')
def test_func(self):
a = self.request.user.username
# print (a)
b = self.kwargs['slug']
# print (b)
x = self.get_object().full_name
# print (x)
y = ''
if a == b:
if x == y:
return True
else:
def get_absolute_url(self):
return reverse('profile:view_profile', kwargs={"slug": self.request.user.username})
class ProfileEdit(LoginRequiredMixin, UserPassesTestMixin, UpdateView):
model = User
form_class = ProfileForm
template_name = "profile/profile_new.html"
slug_field = "username"
def get_login_url(self):
return reverse('account_login')
def test_func(self):
a = self.request.user.username
#print (a)
b = self.kwargs['slug']
#print (b)
x = self.get_object().full_name
#print (x)
y = ''
if a == b:
if x != y:
return True
else:
def get_absolute_url(self):
print("failing")
return reverse('profile:profile_view', kwargs={"slug": self.request.user.username})
Explanation The LoginRequiredMixin forces the user to login. UserPassesTestMixin checks
if full_name is ''(empty)
if the loggedin user's username is same as the slug field
The test_func() is all correct when it returns True, but in the elseloop ie., if the test condition fails the view should redirect to 'profile_view' but it does not do so. i get the output "failing" in the terminal. only when i do the same inside the get_absolute_url() function it does not work. The complete get_absolute_url() function does not work. What am i doing wrong here?
note: the total process seems to be in a loop here
GET /user1/edit/ HTTP/1.1" 302 0
GET /as/login/?next=/user1/edit/ HTTP/1.1" 302 0
these two URLS keep looping.