这是返回错误。 (django 1.5)

时间:2014-01-28 01:41:58

标签: django

**

  

这是它返回的ValueError。风景   poster.views.post_tweet没有返回HttpResponse对象

**
     海报/ views.py

 from django.http import HttpResponseRedirect

 def post_tweet(request, tweet_id=None):
     tweet = None
     if tweet_id:
        tweet = get_object_or_404(Tweet, id=tweet_id)
     if request.method == 'POST':
         form = TweetForm(request.POST, instance=tweet)
         if form.is_valid():
             new_tweet = form.save(commit=False)
             new_tweet.state = 'pending'
             new_tweet.save()
             send_review_email(tweet)
             return HttpResponseRedirect('/post/thankyou/')
     else:
         form = TweetForm(instance=tweet)
         return render(request,'post_tweet.html',{'form': form})

 def thank_you(request):
     tweets_in_queue = Tweet.objects.filter(
        state='pending').aggregate(Count('id')).values()[0]
     return render(request, 'thank_you.html',
         {'tweets_in_queue': tweets_in_queue})
  

的myproject / urls.py

 url(r'^post/', include('poster.urls'))
  

海报/ urls.py

 url(r'^thankyou', 'thank_you'),

1 个答案:

答案 0 :(得分:0)

如果是POST,但表单无效,则表示您没有返回任何内容。如果将return render(request,'post_tweet.html',{'form': form})左移一个缩进级别,它应该都可以正常工作。