0

I dunno whats is happening with my flask ... when I tried to post form it always 301 and redirect into get method

okay here's the my flask code of

    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'])

variable app is represent of Flask app,and when I tried to submit it always ended up with response 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 -

end here's the 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>
davidism
  • 121,510
  • 29
  • 395
  • 339
Elunemoon
  • 23
  • 4

0 Answers0