尚未解决的“自我”参考

时间:2014-10-10 00:17:59

标签: python python-2.7

我无法弄清楚为什么它会显示一个未解决的“自我”的参考资料。在form_head,form_body和form_foot位之后......它不允许Google Engine应用程序显示并正确运行。任何帮助都会有所帮助。

import webapp2

class MainHandler(webapp2.RequestHandler):
    def get(self):

#web page sections
    form_head='''<!DOCTYPE html>
    <html>
      <head>
        <meta charset="utf-8" />
          <link href='http://fonts.googleapis.com/css?family=Roboto' rel='stylesheet'     type='text/css'>
          <link href="css/style.css" rel="stylesheet" type="text/css" />
      <title>Gamers R' Us Subscribing</title>
      </head>
      <body>'''
form_body='''
  <div class="maincontainer">
    <h1>Welcome to Gamers R' Us!</h1>
    <div id="bgimg">
      <p>Filler atm.</p>
      <div id="formbox">
        <h2>Subscribe Today!</h2>
        <form method="GET">
        <label>Full Name: </label><input type="text" name="name" placeholder=" John Doe"/><br>
        <label>Email: </label><input type="text" name="email" placeholder=" me@domain.com"/><br>
        <select name="system" class="selectbox">
          <option value="ps4">Playstation 4</option>
          <option value="xbone">Xbox One</option>
          <option value="wiiu">Wii U</option>
          <option value="pc">PC Gaming</option>
        </select><br>
        <input type="radio" name="genre" value="FPS">First Person Shooter.<br>
        <input type="radio" name="genre" value="MOBA">Multiplayer Online Battle Arena.<br>
        <input type="radio" name="genre" value="RPG">Role-Playing Game.<br>
        <input type="radio" name="genre" value="RTS">Real Time Strategy.<br>
        <input type="radio" name="genre" value="Other">Other Genre.<br>
        <input type="checkbox" name="subscribe" value="yes" checked>Subscribe for gaming updates and more!<br>
        <input type="submit" class="subbtn" value="Done" />
        </form>
      </div>
    </div>
  </div>'''
form_foot='''
  </body>
</html>'''

#if GET is requested it should display on next screen.
#else should load page.
if self.request.GET:
  name= self.request.GET['name']
  email= self.request.GET['email']
  system= self.request.GET['system']
  genre= self.request.GET['genre']
  subscribe= self.request.GET['subscribe']

#displays form information submitted by user.
  self.response.write(form_head + "<div class='maincontainer'>" +
    '<h1>Thanks for Subbing!</h1>' +
    '<div id="infobox">' +
    '<h2></h2>' +
    "Name: "+name+"<br />" +
    "Email: "+email+"<br />" +
    "Preferred System: "+system+"<br /> " +
    "Preferred Genre: "+genre+
    '</div>' +
    '</div>' +
    form_foot)

#Will display error. ** PLACE HOLDER **
else:
  self.response.write("Help! Error!")

# Do not touch this.
app = webapp2.WSGIApplication([
('/', MainHandler)
], debug=True)

1 个答案:

答案 0 :(得分:0)

这里你的代码正确缩进(据我所知)。

我已经更新了我之前的答案,以展示如何使用textwrap.dedent()删除多余的缩进,这些缩进通常需要使大型内联文本块与缩进代码混合更具可读性。另外,我修改了末尾附近的self.response.write()语句,以显示将多个文本变量值替换为长字符串的更简洁方法。

import textwrap
import webapp2

class MainHandler(webapp2.RequestHandler):
  def get(self):
    #web page sections
    form_head=textwrap.dedent('''
      <!DOCTYPE html>
      <html>
        <head>
          <meta charset="utf-8" />
            <link href='http://fonts.googleapis.com/css?family=Roboto' rel='stylesheet' type='text/css'>
            <link href="css/style.css" rel="stylesheet" type="text/css" />
        <title>Gamers R' Us Subscribing</title>
        </head>
        <body>''')

    form_body=textwrap.dedent('''
          <div class="maincontainer">
            <h1>Welcome to Gamers R' Us!</h1>
            <div id="bgimg">
              <p>Filler atm.</p>
              <div id="formbox">
                <h2>Subscribe Today!</h2>
                <form method="GET">
                <label>Full Name: </label><input type="text" name="name" placeholder=" John Doe"/><br>
                <label>Email: </label><input type="text" name="email" placeholder=" me@domain.com"/><br>
                <select name="system" class="selectbox">
                  <option value="ps4">Playstation 4</option>
                  <option value="xbone">Xbox One</option>
                  <option value="wiiu">Wii U</option>
                  <option value="pc">PC Gaming</option>
                </select><br>
                <input type="radio" name="genre" value="FPS">First Person Shooter.<br>
                <input type="radio" name="genre" value="MOBA">Multiplayer Online Battle Arena.<br>
                <input type="radio" name="genre" value="RPG">Role-Playing Game.<br>
                <input type="radio" name="genre" value="RTS">Real Time Strategy.<br>
                <input type="radio" name="genre" value="Other">Other Genre.<br>
                <input type="checkbox" name="subscribe" value="yes" checked>Subscribe for gaming updates and more!<br>
                <input type="submit" class="subbtn" value="Done" />
                </form>
              </div>
            </div>
          </div>''')

    form_foot=textwrap.dedent('''
        </body>
      </html>''')

    #if GET is requested it should display on next screen.
    #else should load page.
    if self.request.GET:
      name=self.request.GET['name']
      email=self.request.GET['email']
      system=self.request.GET['system']
      genre=self.request.GET['genre']
      subscribe=self.request.GET['subscribe']

      #displays form information submitted by user.
      self.response.write(form_head +
                          textwrap.dedent('''
                            <div class='maincontainer'>
                              <h1>Thanks for Subbing!</h1>
                              <div id="infobox">
                                <h2></h2>
                                Name: {name}<br />
                                Email: {email}<br />
                                Preferred System: {system}<br />
                                Preferred Genre: {genre}
                              </div>
                            </div>''').format(**locals()) +
                          form_foot)

    #Will display error. ** PLACE HOLDER **
    else:
      self.response.write("Help! Error!")

# Do not touch this.
app = webapp2.WSGIApplication([('/', MainHandler)], debug=True)