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

329
Views
Django UserPassesTestMixin, ¿Error de bucle en get_absolute_url?

Vistas.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})

Explicación LoginRequiredMixin obliga al usuario a iniciar sesión. Controles UserPassesTestMixin

  1. si nombre_completo es ''(vacío)

  2. si el nombre de usuario del usuario que inició sesión es el mismo que el campo slug

test_func() es todo correcto cuando devuelve True, pero en el bucle else , es decir, si la condición de prueba falla, la vista debería redirigir a 'profile_view' pero no lo hace. Obtengo la salida "failing" en la terminal. solo cuando hago lo mismo dentro de la función get_absolute_url() no funciona. La función get_absolute_url() completa no funciona. ¿Qué estoy haciendo mal aquí?

nota: el proceso total parece estar en un bucle aquí

  1. OBTENER /usuario1/editar/HTTP/1.1" 302 0

  2. GET /as/login/?next=/usuario1/editar/HTTP/1.1" 302 0

estas dos URLS siguen en bucle.

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!