Python网站显示页面

时间:2015-10-08 19:57:00

标签: python html google-app-engine

我正在尝试创建一个简单的Web应用程序,它将使用html和python来允许人们在表单上输入信息并将数据存储在数据存储中。我已经完成了谷歌演练,当我使用他们的python /模板代码时,我可以加载我的html页面,但我的代码我不能。我猜我错过了一些明显的东西。

# [START imports]
import os
import urllib

from google.appengine.ext import ndb

import jinja2
import webapp2


JINJA_ENVIRONMENT = jinja2.Environment(
    loader=jinja2.FileSystemLoader(os.path.dirname(__file__)),
    extensions=['jinja2.ext.autoescape'],
    autoescape=True)
# [END imports]

class Playerinfo(ndb.model):
    name = ndb.StringProperty()
    weight= ndb.IntegerProperty()
    email= ndb.StringProperty()
    position = ndb.StringProperty()
    age18= nbd.BooleanProperty()



# [START main_page]
class MainPage(webapp2.RequestHandler):

    def get(self):
        self.query = Playerinfo.all()
        template_values=
        {
            'pname': self.playerinfo.name,
            'pweight': self.playerinfo.weight,
            'pemail': self.playerinfo.email,
            'pposition': self.playerinfo.position,
            'page18': self.playerinfo.age18
        }

        template = JINJA_ENVIRONMENT.get_template('index.html')
        self.response.write(template.render(template_values))

    def post(self):
        self.playerinfo= Playerinfo(name=self.request.get('name'))
        self.playerinfo= Playerinfo(weight=self.request.get('weight'))
        self.playerinfo= Playerinfo(name=self.request.get('email'))
        self.playerinfo= Playerinfo(weight=self.request.get('position'))
        self.playerinfo= Playerinfo(weight=self.request.get('age18'))
# [END main_page]



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

HTML index.html

<!DOCTYPE html>
{% autoescape true %}
<html>
  <body>
    <h1>Player Information</h1>
    <form action="/" method="post">
    <p><label>Name: <input type="text" name="name"></label></p>
    <p><label>Weight: <input type="number" name="weight"></label></p>
    <p><label>E-mail address: <input type=email name="email"></label></p>
    <fieldset>
    <legend> Position </legend>
  <p><label> <input type=radio name=position value=inf> Infield </label></p>
  <p><label> <input type=radio name=position value=of> Outfield </label></p>
  <p><label> <input type=radio name=position value=pitcher> Pitcher </label></p>
 </fieldset>
 <fieldset>
  <legend> Age </legend>
  <p><label> <input type=checkbox name=age18> Under 18 </label></p>
 </fieldset>
</form>

  </body>
</html>
{% endautoescape %}

0 个答案:

没有答案