Django错误。 KeyError' new_article'

时间:2014-12-14 23:07:03

标签: python django

这是我的代码:

def render_new_article(request):
    if request.method == "POST":

    step_number = int(request.POST.get("step_number", ""))
    new_article = request.session['new_article']

    if 'prev' in request.POST:
        step_number = step_number - 1

    elif 'next' in request.POST:
        if step_number == 0:
            print type(new_article.steps)
            new_article.title = request.POST.get("title", "")
            new_article.description = request.POST.get(
                "description", "")
        else:
            print type(new_article.steps)
            new_article.steps[int(step_number)] = request.POST.get(
                "step_description", "")

        request.session['new_article'] = new_article
        step_number = step_number + 1

    elif 'publish' in request.POST:
        new_article.draft = False
        draft_article = Article.objects.filter(
            parent_id=new_article.pk).exclude(parent_id=None)[:1]
        if len(draft_article) > 0:
            draft_article[0].delete()
        new_article.full_clean()
        new_article.save()
        del request.session['new_article']
        return HttpResponseRedirect("/article?articleid=" + str(new_article.pk))

    c = RequestContext(request, {
        'user': request.user, 'step_number': step_number,
        'article': new_article,
    })
    return render_to_response("new_article.html", c)
else:
    # This function renders the home.
    article_id = request.GET.get('article_id', '')

    user = User.objects.get(id=request.user.pk)
    app_user = AppUser.objects.get(user=user)
    new_article = Article(created_by=app_user, steps={}, id=None,
                          draft=True, parent_id=None, pk=None)

    if article_id.strip() != '':
        new_article = Article.objects.get(pk=article_id)
        new_article.steps = ast.literal_eval(new_article.steps)
        print "getting article from DB"

    request.session['new_article'] = new_article
    c = RequestContext(request, {
        'user': request.user, 'step_number': 0,
        'article': new_article,
    })
    return render_to_response("new_article.html", c)

每当我尝试在Openshift上运行它时,这会给我一个错误,但它在本地工作正常。我也检查了Django版本和Python版本。

0 个答案:

没有答案