[英]AttributeError: 'function' object has no attribute 'method' for if request.method == "POST":
Running Flask its giving me an error message pointing toward:运行 Flask 它给了我一条错误消息,指向:
if request.method == "POST":
This is my error:这是我的错误:
AttributeError: 'function' object has no attribute 'method'
I'm confused because I've used the same code for another application and it works.我很困惑,因为我在另一个应用程序中使用了相同的代码并且它可以工作。 I'm a complete newbie.
我是一个完全的新手。
This is app.py:这是 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')
This is my index.html:这是我的索引。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>
flask.request是未绑定的LocalProxy,但request.request是一个函数
Make sure suppose you should enter the function call,确保假设您应该输入 function 调用,
from requests import request从请求导入请求
Please remove the line and check.请删除线路并检查。
i had the same issue.我遇到过同样的问题。 The problem was python was confusing flask.request, with requests.request.
问题是 python 混淆了 flask.request 和 requests.request。 Try checking that out, worked for me.
尝试检查一下,为我工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.