2012-05-01 10 views
0

内部サーバーエラー「BadValueError:プロパティーの内容は必須です。 blog_tableをレンダリングするためにテンプレートに渡すと起こるようです。内部サーバーエラー - Google App Server(プロパティーコンテンツが必要)

main.py:

import os 
import webapp2 
import jinja2 

from google.appengine.ext import db 

jinja_env = jinja2.Environment(loader = jinja2.FileSystemLoader(os.path.join(os.path.dirname(__file__),'templates')), autoescape = True) 

class Handler(webapp2.RequestHandler): 
    def write(self,*a,**kw): 
     self.response.out.write(*a,**kw) 

    def render_str(self,template,**params): 
     t = jinja_env.get_template(template) 
     return t.render(params) 

    def render(self,template,**kw): 
     self.write(self.render_str(template,**kw)) 

class Blog(db.Model): 
    subject = db.StringProperty(required = True) 
    content = db.TextProperty(required = True) 
    created = db.DateTimeProperty(auto_now_add = True) 

class MainPage(Handler): 
    def render_front(self, subject="", content="", error=""): 
     blog_table = db.GqlQuery("SELECT * FROM Blog ORDER BY created DESC") 
     self.render("blog.html",subject = subject,content = content,error = error,blog_table = blog_table) 

    def get(self): 
     self.render_front() 

    def post(self): 
     subject = self.request.get("subject") 
     content = self.request.get("content") 

     if subject and content: 
      b = Blog(subject = subject, content = content) 
      b.put() 
      self.redirect("/") 

     else: 
      error = "we need both a subject and some content" 
      self.render_front(subject,content,error) 

app = webapp2.WSGIApplication([('/', MainPage)],debug=True) 

HTML:

<!DOCTYPE html> 

<html> 
    <head> 
     <title>Blog</title> 
    </head> 
    <body> 
     <h1>Blog</h1> 

     <form method="post"> 
      <label> 
       <div>Subject</div> 
       <input type="text" name="subject" value="{{subject}}"> 
      </label> 
      <label> 
       <div>Content</div> 
       <textarea name="content" value="{{content}}"></textarea> 
      </label> 
      <div class="error">{{error}}</div> 
      <input type="submit"> 
     </form> 

     <hr> 
    {% for post in blog_table %} 
     <div class="post"> 
      <div class="subject">{{post.subject}}</div> 
      <pre class="content">{{post.content}}</pre> 
     </div> 
    {% endfor %} 

    </body> 
</html> 

エラーがhttp://udacity-cs253-a31.appspot.com/

おかげに行く見るにはここをクリックしてくださいコードです。

+0

私のために働いた... – Nix

+0

blog_tableをself.renderに渡さないと動作しますが、出力を表示します。それを試して、エラーを見てください。ありがとう。 – GawecoT

+0

私はそれを試してもエラーはありませんか?それが失敗するのを見るために私は何を入力すべきですか? – Nix

答えて

4

これはちょうど推測です - あなたのブログモデルを変更し、最近コンテンツ属性を追加しました。

データストアには、コンテンツを持たないBlogモデルの古いインスタンスがいくつかあります。それらをロードしようとすると、コードが失敗します。 ContentでBlogインスタンスを読み込んだ場合は、すべて問題ありません。

データストアを経由して、ブログのすべてのインスタンスにコンテンツがあることを確認する必要があります。

+0

これはうまくいくようです。データベースをフラッシュします。私は投票をしようとしましたが、私は評判がありません。ありがとう! – GawecoT

+0

@ GawecoTデータベースをどのようにフラッシュしましたか? – Chris

関連する問題