python flask bucketlist应用程序

I am attempting to build a python flask web app with a tutorial and I am having trouble implementing my signUp method. Tutorial:

I get a 500 error when I hit the 'sign up' button: _name = Request.form['inputName'] TypeError: 'cached_property' object has no attribute 'getitem'

Not sure why I am receiving 500 error. Any help would be appreciated. Thanks

Below is my python code:

from flask import Flask, render_template, json, Request

app = Flask(__name__)

def main():
    return render_template('index.html')

def showSignUp():
    return render_template('signup.html')

def signUp():
    _name = Request.form['inputName']
    _email = Request.form['inputEmail']
    _password = Request.form['inputPassword']

    if _name and _email and _password:
        return json.dumps({'html':'<span>All fields good !!</span>'})
        return json.dumps({'html:':'<span>Enter the required fields</span>'})

if __name__ == "__main__":

Here is the javascript ajax code:

$(function () {
    $('#btnSignUp').click(function () {
            url: '/signUp',
            data: $('form').serialize(),
            type: 'POST',
            success: function(response) {
            error: function(error) {

Here is signup.html

<!DOCTYPE html>
<html lang="en">
        <title>Python Flask Bucket List App</title>

        <link href="" rel="stylesheet" />
        <link href="" rel="stylesheet" />
        <link href="../static/signup.css" rel="stylesheet" />
        <script src="../static/js/jquery-3.1.0.js"></script>
        <script src="../static/js/signUp.js"></script>



        <div class="container">
            <div class="header">
                    <ul class="nav nav-pills pulls-right">
                        <li role="presentation"><a href="main">Home</a></li>
                        <li role="presentation"><a href="#">Sign In</a></li>
                        <li role="presentation" class="active"><a href="#">Sign Up</a></li>
                <h3 class="text-muted">Python Flask App</h3>

            <div class="jumbotron">
                <h1>Bucket List App</h1>
                <form class="form-signin">
                <label for="inputName" class="sr-only">Name</label>
                <input type="name" name="inputName" id="inputName" class="form-control" placeholder="Name" required autofocus />
                <label for="inputEmail" class="sr-only">Email address</label>
                <input type="email" name="inputEmail" id="inputEmail" class="form-control" placeholder="Email address" required autofocus />
                <label for="inputPassword" class="sr-only">Password</label>
                <input type="password" name="inputPassword" id="inputPassword" class="form-control" placeholder="Password" required />

                <button id="btnSignUp" class="btn btn-lg btn-primary btn-block" type="button">Sign up</button>

            <footer class="footer">
                <p>&copy; Company 2016</p>



最近在实现相同功能时也遇到了相同的问题。</ p>

在app.py中更改注册代码,如下所示,包括导入。</ p>



def signUp():
     _name = request.form ['inputName']
     _email = request.form ['inputEmail']
     _password = request.form ['inputPassword']
</ code> </ pre>

注意:它应该是 request </ code>而不是 Request </ code> </ p>

</ p>

因为 Request </ code>是Flask用来表示传入请求的类,所以会发生此错误。 但是,它不是请求本身。 相反,Flask将当前请求存储为 request </ code>变量,该请求是 Request </ code>类的实例。
     </ div>



I also encountered the same issue when I was implementing the same recently.

Change your signUp code in as follows including the import.

from flask import Flask, render_template, json, request

def signUp():
    _name = request.form['inputName']
    _email = request.form['inputEmail']
    _password = request.form['inputPassword']

Note: it should be request not Request

This error occurs because Request is the class Flask uses to represent an incoming request; it is not, however, the request itself. Instead, Flask stores the current request, which is an instance of the Request class, in the request variable.

Csdn user default icon