尝试登录时出现错误405.Flask

时间:2015-07-28 15:14:48

标签: python flask

我使用Python 2.7和Flask with Bootstrap:

当我登录我的网站时,提交我的用户名和密码后会显示405 Method Not Allowed页面。它们确实存在于数据库中,页面至少应显示错误消息。

init .py中的登录功能:

@app.route('/login/', methods = ['GET','POST'])
def login():
try:
    c, conn = connection()
    error = None

    if request.method == 'POST':

        data = c.execute("SELECT * FROM users WHERE username = (%s)",
                        thwart(request.form['username']))
        data = c.fetchone()[2]

        if sha256_crypt.verify(request.form['password'], data):
            session['logged_in'] = True
            session['username'] = request.form['username']

            flash("Welcome "+str(session['username'])+"! You are now logged in.")
            return redirect(url_for("dashboard"))

        else:
            error = "Invalid credentials, try again."

    gc.collect()

    return render_template('login.html', error = error)

except Exception as e:
    flash(e)
    error = "Invalid credentials, try again."
    return render_template('login.html', error = error)

这是我的login.html文件:

{% extends "header.html" %}

{% block body %}
<body>

<div class="container">

    <br>

    <h4>Please Login:</h4>
    <br>
    <form action="" class="form-inline" method="post">
        <input type="text" class="form-control" placeholder = "Username" name="username" value="{{request.form.username}}">
        <input type="password" class="form-control" placeholder = "Password" name="password" value="{{request.form.password}}">
        <input class="btn btn-default" type="submit" value="Login">
    </form>

    {% if error %}
        <p class="error"><strong>Error:</strong> {{ error }}</p>
    {% endif %}
    <div class="container">
        <br>
        <p>No account? <a href='/register'>Register here</a>.</p>
        <br>
        {% for paragraph in Body_info %}
        <p>{{ paragraph }}</p>
        {% endfor %}
    </div>

</div>

</body>

{% endblock %}

0 个答案:

没有答案