在發佈表單數據和使用webapp2處理數據時遇到了一些問題。webapp2 - 如何發佈表單數據 - 應用引擎
我不確定如何處理webapp2中的表單中的數據,包括將表單操作發佈到哪個頁面。
我的表單位於'/ schedule/create-consult'頁面上。我最初正在測試提交前兩個字段到同一頁面(即名字和姓氏發佈到/ schedule/create-consultults)。
我的形式看起來像這樣
<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>
當我點擊保存按鈕我得到的消息:
405不允許的方法 - POST方法是不允許進行這種資源。
我的路線是這樣的
app = webapp2.WSGIApplication([
('/', MainPage),
('/schedule', SchedulePage),
('/consults', ConsultsPage),
('/schedule/create-consult', CreateConsultPage),
('/consults/john-smith-030617-0930', JohnSmithPage)
], debug=True)
我對CreateConsultsPage處理程序看起來像這樣
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
的可能的複製[405不允許的方法的方法,POST不允許該資源的AppEngine Facebook應用](http://stackoverflow.com/questions/13346309/405-method-not-allowed-the- method-post-is-not-allowed-for-this-resource-appengin) –
def get(self):和下一行之間應該有一個縮進 –