1

我正在制作一个博客页面,在每个页面的底部都会收到一条消息。

消息说:
“” * * 403 Fobidden

  • 代码:拒绝访问
  • 消息:拒绝访问
  • 请求编号:12D5257EEFBC8528
  • 主机ID:**
    **""

请指引我的路

我的 ROUTE PAGE 包含的连接如下:

from flask import *
from functools import wraps
import sqlite3

DATABASE = 'message.db'

app = Flask(__name__)
app.config.from_object(__name__)

app.secret_key = "my key"

def connect_db():
    return sqlite3.connect(app.config['DATABASE'])

@app.route('/')
def home():
    return render_template('home.html')

@app.route('/message')
def message():
    g.db = connect_db()
    cur = g.db.execute('select msg_msg from msg')
    message = [dict(msg_msg=row[0]) for row in cur.fetchall()]
    g.db.close()
    return render_template('message.html', message=message)


def login_required(test):
    @wraps(test)
    def wrap(*args, **kwargs):
        if 'logged_in' in session:
            return test(*args, **kwargs)
        else:
            flash('You need to Login First.')
            return redirect(url_for('log'))
    return wrap

@app.route('/logout')
def logout():
    session.pop('logged_in', None)
    flash('You were logged out')
    return redirect(url_for('log'))


@app.route('/hello')
@login_required
def hello():
    g.db = connect_db()
    cur = g.db.execute('select msg_msg from msg')
    message = [dict(msg_msg=row[0]) for row in cur.fetchall()]




@app.route('/log', methods=['GET', 'POST'])
def log():
    error = None
    if request.method == 'POST':
        if request.form['username'] != 'admin' or request.form['password'] != 'admin':
            error = 'Invalid Entry, Please Try Again.'
        else:
            session['logged_in'] = True
            return redirect(url_for('hello'))
        return render_template('log.html' , error=error)


@app.route('/add', methods=['POST'])
def add_entry():
    g.db = connect_db()
    cur = g.db.execute('insert into msg (msg_msg) values (?)', [request.form['input_msg']])
    g.db.commit()
    flash('New Entry was SUCCESSFULLY POSTED.')
    return redirect(url_for('message'))


if __name__ == '__main__':
    app.run(debug=True)
4

0 回答 0