Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

330
Views
Django UserPassesTestMixin, Looping error in get_absolute_url?

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

  1. if full_name is ''(empty)

  2. 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

  1. GET /user1/edit/ HTTP/1.1" 302 0

  2. GET /as/login/?next=/user1/edit/ HTTP/1.1" 302 0

these two URLS keep looping.

over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!