用方法贴在烧瓶中的路线,总是得到301响应

时间:2017-06-30 12:55:15

标签: python http redirect flask routes

我不知道我的烧瓶发生了什么......当我试图发布表格总是301并重定向到get方法

好的,这是我的烧瓶代码

    class AuthController(object):
        def __init__(self):
            super(AuthController, self).__init__()
            self.view_page = 'auth.html'

        def view(self):
            return render_template(self.view_page)

        def post(self):
            if self.request.form['password'] == 'password' and self.request.form['username'] == 'admin':
                print True
            else:
                print 'wrong password!'

    class DashboardController(object):
        def __init__(self):
            super(DashboardController, self).__init__()
            self.view_page = 'dashboard.html'

        def view(self):
            return render_template(self.view_page)

app.add_url_rule('/', endpoint='index', view_func='view')
app.add_url_rule('/auth/', endpoint='auth', view_func='view')
app.add_url_rule('/auth/post/', endpoint='post', methods=['POST'])

变量应用程序代表Flask应用程序,当我尝试提交时,它总是以响应301结束

 flask run --host=0.0.0.0
 * Serving Flask app "main"
 * Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
127.0.0.1 - - [30/Jun/2017 19:40:41] "GET /auth/ HTTP/1.1" 200 -
127.0.0.1 - - [30/Jun/2017 19:40:41] "GET /favicon.ico HTTP/1.1" 404 -
127.0.0.1 - - [30/Jun/2017 19:40:44] "POST /auth/post HTTP/1.1" 301 -
127.0.0.1 - - [30/Jun/2017 19:40:44] "GET /auth/post/ HTTP/1.1" 405 -

这里是auth.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <form action="/auth/post" method="post">
        <input type="text" name="username" placeholder="username" class="form form-input"/>
        <input type="password" name="password" placeholder="password" class="form form-input"/>
        <button type="submit">Go</button>
    </form>
</body>
</html>

0 个答案:

没有答案