运行Flask,给我一条错误信息指向:
if request.method == "POST":
这是我的错误:
AttributeError: 'function' object has no attribute 'method'
我感到很困惑,因为我已将相同的代码用于其他应用程序,但它确实有效。我是一个完整的新手。
这是app.py:
from __future__ import print_function
from flask import Flask, render_template, flash, request, url_for, redirect, session, g
import controllers
import config
from functools import wraps
import argparse
import json
import pprint
import requests
import sys
import urllib
# this client code can run on Python 2.x or 3.x. Your imports can be
# simpler if you only need one of those.
try:
# For Python 3.0 and later
from urllib.error import HTTPError
from urllib.parse import quote
from urllib.parse import urlencode
except ImportError:
# Fall back to Python 2's urllib2 and urllib
from urllib2 import HTTPError
from urllib import quote
from urllib import urlencode
@app.route('/', methods=["GET","POST"])
def main_route():
if request.method == "POST":
input_place = request.form['location']
input_type = request.form['type']
return render_template('index.html')
return render_template('index.html')
这是我的index.html:
<form class="form-inline" method="post">
<input type="text" class="form-control" placeholder="Zip Code or City" name="location_zip" value="{{request.form.location}}">
<input type="text" class="form-control" placeholder="Type of Establishment" name="type_place" value="{{request.form.type}}">
<input class="btn btn-link" type="submit" value="Submit">
</form>
答案 0 :(得分:0)
flask.request是未绑定的LocalProxy,但request.request是一个函数