Flask MethodView def post中没有请求对象(个体经营)

时间:2014-02-04 02:54:58

标签: python html5 flask

我正在尝试使用基于类的MethodView将html5表单发送到烧瓶。根据我的理解,def post(self):应该包含一个带有表单属性的请求对象。但是,当我尝试以下代码时,我得到"NameError: global name 'request' is not defined"

烧瓶中:

from app import app
from flask.views import MethodView
from app import app
from flask.views import MethodView

from flask import url_for

@app.route('/')
def index():
        return app.send_static_file('index.html')


class ImageShareForm(MethodView):

    def get(self):
        pass

    def post(self):
        print (request)


app.add_url_rule('/imageshareform/', view_func=ImageShareForm.as_view('imageshareform'))

HTML:

<form method="POST">
    <div class="form-group btn-group-ls well col-md-5">
        <legend>Region</legend>
        <input class="form-inline" type="radio" name="regions" id="IAD" value="IAD" checked>
        <label for="IAD" class="btn btn-default region">Virginia</label>
        <input class="form-inline" type="radio" name="regions" id="ORD" value="ORD">
        <label for="ORD" class="btn btn-default region">Chicago</label>
        <input class="form-inline" type="radio" name="regions" id="DFW" value="DFW">
        <label for="DFW" class="btn btn-default region">Dallas</label>
        <input type="radio" id="HKG" name="regions" value="HKG">
        <label for="HKG" class="btn btn-default region">Hong Kong</label>
    </div>
    <div class="form-group well col-md-5">
        <label for="producerUsername">Producer Username</label>
        <input type="text" class="form-control" id="producerUsername" placeholder="Enter producer's username" >
        <label for="producerApiKey">Producer Api Key</label>
        <input type="text" class="form-control" id="producerApiKey" placeholder="Enter producer's api key" >
    </div>
    <div class="form-group well col-md-5">
        <label for="consumerUsername">Consumer Username</label>
        <input type="text" class="form-control" id="consumerUsername" placeholder="Enter consumer's username" >
        <label for="consumerApiKey">Consumer Api Key</label>
        <input type="text" class="form-control" id="consumerApiKey" placeholder="Enter consumer's api key" >
    </div>
    <div class="form-group well col-md-5">
        <label for="imageUuid">Image UUID</label>
        <input type="text" class="form-control" id="imageUuid" placeholder="Enter images's image Uuid" >
    </div>
    <div class="col-md-5">
        <input type="submit" value="Submit" class="btn btn-primary" formenctype="multipart/form-data" formaction="/imageshareform">
    </div>
</form>

1 个答案:

答案 0 :(得分:3)

发现我需要导入Flask附带的请求