Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/google-app-engine/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/229.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 2.7 webapp2-如何发布表单数据-应用程序引擎_Python 2.7_Google App Engine_Webapp2 - Fatal编程技术网

Python 2.7 webapp2-如何发布表单数据-应用程序引擎

Python 2.7 webapp2-如何发布表单数据-应用程序引擎,python-2.7,google-app-engine,webapp2,Python 2.7,Google App Engine,Webapp2,从表单发布数据并使用webapp2处理数据时遇到问题 一般来说,我不确定如何在webapp2中处理表单中的数据,包括使用表单操作将数据发布到哪个页面 我的表格在“/schedule/create consult”页上。我最初测试将前两个字段提交到同一个页面(即,将名字和姓氏发布到/schedule/create consults) 我的表格是这样的 <form method="post" action="/schedule/create-consult"> <div c

从表单发布数据并使用webapp2处理数据时遇到问题

一般来说,我不确定如何在webapp2中处理表单中的数据,包括使用表单操作将数据发布到哪个页面

我的表格在“/schedule/create consult”页上。我最初测试将前两个字段提交到同一个页面(即,将名字和姓氏发布到/schedule/create consults)

我的表格是这样的

<form method="post" action="/schedule/create-consult">
    <div class="row">
        <div class="col-md-6">
            <label>First Name</label>
            <input class="form-control input-lg" type="text" name="first_name" />
            <br/>
        </div>
        <div class="col-md-6">
            <label>Last Name</label>
            <input class="form-control input-lg" type="text" name="last_name" />
        </div>
        <input type="submit" value="save">
    </div>
</form>
app = webapp2.WSGIApplication([
    ('/', MainPage),
    ('/schedule', SchedulePage),
    ('/consults', ConsultsPage),
    ('/schedule/create-consult', CreateConsultPage),
    ('/consults/john-smith-030617-0930', JohnSmithPage)
], debug=True)
class CreateConsultPage(webapp2.RequestHandler):
    def get(self):
    template = JINJA_ENVIRONMENT.get_template('/templates/create-consult.html')  
    self.response.out.write(template.render())
我的CreateConsultsPage处理程序如下所示

<form method="post" action="/schedule/create-consult">
    <div class="row">
        <div class="col-md-6">
            <label>First Name</label>
            <input class="form-control input-lg" type="text" name="first_name" />
            <br/>
        </div>
        <div class="col-md-6">
            <label>Last Name</label>
            <input class="form-control input-lg" type="text" name="last_name" />
        </div>
        <input type="submit" value="save">
    </div>
</form>
app = webapp2.WSGIApplication([
    ('/', MainPage),
    ('/schedule', SchedulePage),
    ('/consults', ConsultsPage),
    ('/schedule/create-consult', CreateConsultPage),
    ('/consults/john-smith-030617-0930', JohnSmithPage)
], debug=True)
class CreateConsultPage(webapp2.RequestHandler):
    def get(self):
    template = JINJA_ENVIRONMENT.get_template('/templates/create-consult.html')  
    self.response.out.write(template.render())
我的app.yaml如下:

 runtime: python27
 api_version: 1
 threadsafe: true

 handlers:
 - url: /css
   static_dir: css
 - url: /images
   static_dir: images
 - url: /js
   static_dir: js
 - url: /
   script: main.app
 - url: /schedule
   script: main.app
 - url: /consults
   script: main.app
 - url: /schedule/create-consult
   script: main.app
 - url: /consults/john-smith-030617-0930
   script: main.app

 libraries:
 - name: webapp2
   version: latest
 - name: jinja2
   version: latest

它正在尝试向你的应用程序发送帖子,但你没有配置接收该帖子的处理程序

获取处理程序的位置:

class CreateConsultPage(webapp2.RequestHandler):
     def get(self):
         dostuf
你还需要有一个投手:

class CreateConsultPage(webapp2.RequestHandler):
    def post(self):
        dostuff

您正在使用post方法提交表单。您必须在处理程序类中定义post函数以获取提交的表单数据。这会解决你的问题

class CreateConsultPage(webapp2.RequestHandler):
    def get(self):
        template = JINJA_ENVIRONMENT.get_template('/templates/create-consult.html')  
        self.response.out.write(template.render())

    def post(self):
        first_name = self.request.get('first_name')
        last_name = self.request.get('last_name')

def get(self):和下一行之间应该有缩进