user3782831
user3782831

Reputation: 45

TypeError: 'in <string>' requires string as left operand, not QueryDict

While updating the edited blog i am getting this error: in edit_article function Here is my function,

def edit_article(request, id):
    session_start(request)
    if Article.exists(id):
        article = Article.getByName(id)
    else:
        article = Article(id)
    if request.method == 'POST' and request.POST in "content":
        if has_article_access(request, article):
            article.body = request.POST['content']
            article.save()
            if 'counter_edit' in request.session:
                request.session['counter_edit'] += 1
            else:
                request.session['counter_edit'] = 1
            delete_article_locked(request, article)
            return HttpResponseRedirect('/myblog/?edited')
        else:
            return HttpResponseRedirect('/myblog/?locked')
    else:
        if has_article_access(request, article):
            start_article_locked(request, article)
        else:
            return HttpResponseRedirect('/myblog/?locked')
        return render_to_response("edit.html",
                                  {
                                   'name': article.title,
                                   'content': article.body,
                                   'id':article.id
                                  },
                                  context_instance=RequestContext(request)
        )

The error shows in 7th line.

Upvotes: 0

Views: 173

Answers (1)

xbello
xbello

Reputation: 7443

If you want to check if request.POST has the key "content":

if request.method == 'POST' and "content" in request.POST:

Upvotes: 1

Related Questions