Django TypeError 'QueryDict' object is not callable


Question

I've looked for posts that have endured the same problem that I'm currently facing. But I haven't found a solution. What my problem is:

I have a list of tags. Generated by {% for tag in all_tags %}. Each tag has a tagstatus form. When a user selects an option from a drop down, the form submits and is supposed to save the TagStatus object (Tags are foreignKey'd to TagStatus). However, what returns is this:

Exception Type: TypeError
Exception Value: 'QueryDict' object is not callable

html:

<form class="nice" id="status-form" method="POST" action="">
     {% csrf_token %}
     <input type="hidden" name="status_check" />
     <input type='hidden' name="tag" value="{{ tag }}" />
     <select name="select" id="positionSelect" class="input-text category" onchange="this.form.submit()">
          <option name="all" value="0">Your Status</option>
          <option name="investing" value="1">Status 1</option>
          <option name="selling" value="2">Status 2</option>
          <option name="interested" value="3">Status 3</option>
     </select>
</form>

views.py:

@login_required
def tags(request):
    all_tags = Tag.objects.all()
    context = base_context(request)
    if request.method == 'POST':
        if 'status_check' in request.POST:
            status = request.GET('status')
            tag = request.GET('tag')
            user = request.user
            tag_status, created = TagStatus.objects.get_or_create(status=len(status), tag=tag, user=user).save()

            response = simplejson.dumps({"status": "Successfully changed status"})
        else:
            response = simplejson.dumps({"status": "Error"})
            return HttpResponse (response, mimetype='application/json')
    context['all_tags'] = all_tags
    return render_to_response('tags/tag.html', context, context_instance=RequestContext(request))

models.py (if its relevant):

class TagStatus(models.Model):
    user = models.ForeignKey(User, null=True, unique=True)
    status = models.CharField(max_length=2, choices=tag_statuses)
    tag = models.ForeignKey(Tag, null=True, blank=True)

    def __unicode__(self):
        return self.status

    def save(self, *args, **kwargs):
        super(TagStatus, self).save(*args, **kwargs)

From what I gather it has something to do with the status not being a number. But when I convert it to a int. I get the same error. Please help me. Why is this happening? And whats the fix? I'm not quite sure how to solve this problem. Thank you for your help in advance.

1
2
4/3/2013 10:25:10 PM

Accepted Answer

I believe the error you're encountering is in these lines:

status = request.GET('status')
tag = request.GET('tag')

request.GET is a QueryDict, and adding () after it attempts to "call" a non-callable object. It appears the syntax you're looking for is dictionary lookup syntax instead:

status = request.GET['status']
tag = request.GET['tag']
30
4/3/2013 10:33:18 PM

or just call GETs get to get your values

status = request.GET.get('status')
tag = request.GET.get('tag')

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon