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

201
Vistas
display edit button only if the logged in user is same as the user's page?

example:

1.example.com/username1

2.example.com/username2

i want to take to user to the edit profile page, i got all the permission working correctly and set the views accordingly.

My Problem:

i loggedin as username1 so i should not be able to access example.com/username2/edit/. i got this to work in the views by adding some permissions, but i dont want to display the edit button when the loggedin username1 views the page of username2. Now i use {% if user.is_authenticated %} and this results in display the edit button on page of username2 even though the loggedin user is username1.

Any simple solutions that can be used in the templates directly?

over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

views.py

class CanEditMixin(object):
    def get_context_data(self, **kwargs):
        """
        The method populates Context with can_edit var
        """
        # Call the base implementation first to get a context
        context = super(CanEditMixin, self).get_context_data(**kwargs)
        #Update Context with the can_edit
        #Your logic goes here (something like that)
        if self.request.user.slug == self.kwargs['slug']:
            context['can_edit']=True
        else:
            context['can_edit']=False
        return context

class ProfileView(CanEditMixin, UserPassesTestMixin, DetailView): .....

template.html

{% if can_edit %}
    <a href="#">Edit</a>
{% endif %}
over 4 years ago · Santiago Trujillo Denunciar

0

you can check if request.user is the same as the user that the URL is assigned to. In your request you have a key called 'user' which is your logged one (if logged) or anonymous (if not logged).

{% if user.is_authenticated %} is for checking if the user is authenticated (as the name says), that means if the user is a valid user (for example he clicked the link in the email).

over 4 years ago · Santiago Trujillo Denunciar
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