[Fixed]-Django unable to hide button

1👍

You need to send alreadyfilled parameter in the context of the template.

Since you are not sending this variable, the template always displays the button.

You can create a context dict and pass the context when rendering the template. This will then pass the variable alreadyfilled into the template.

def hello(request, id):
   ....
   try:
        a = ItemHello.objects.get(idx = int(id))
    except ObjectDoesNotExist:
        raise Http404
   alreadyfilled = False
   if a.check_alreadyfilled():
     print alreadyfilled 
     alreadyfilled = True
   ...
   context = {'alreadyfilled': alreadyfilled} # pass the parameter in the context
   return render(request, 'template_name.html', context)

Leave a comment