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

135
Views
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 answers
Answer question

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 Report
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!