Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

334
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda