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

137
Vistas
using querydict item for if-statement

The url: myurl/?page=1&reverse

Now I want to check in the template whether reverse is in there:

{% if request.GET.reverse %}
  do somthing
{% endif %}

But what's in between of if and endif never happens!

What should I use instead of request.GET.reverse?

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

0

Why not put that logic inside your view? Like this:

# Function Based View (FBV)

def my_view(request):
    reversed = request.GET.get('reverse', '')
    return render(request, 'template.html', locals())

# Class Based View (CBV)
class MyView(ListView):
    template_name = 'path/to/template.html'
    queryset = MyModel.objects.filter(...)
    context_object_name = 'my_obj'

    def get_context_data(self, **kwargs):
        context = super(MyView, self).get_context_data(**kwargs)
        context['reversed'] = self.request.GET.get('reverse', '')
        return context

Then do:

{% if reversed %}
    do somthing
{% endif %}

On the other hand, if you still want to do this kind of logic in your template then you should create your own filter like this:

from django import template

register = template.Library()    

def is_in_dict(d, key):
    return key in d

and use it like this:

{% load my_filters %}

{% if request.GET|is_in_dict:"reverse" %}
    do somthing
{% endif %}
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