flaskr 遇到的问题

1. sqlite3.OperationalError: near "create": syntax error

drop table if exists entries;
create table entries (
    id integer primary key autoincrement,
    title string not null,
    text string not null
);

原因: 第一行entries 后面忘了分号;

2. Flask Value error view function did not return a response [duplicate]

@app.route('/login', methods=['GET','POST'])
def login():
    error = None
    if request.method == 'POST':
        if request.form['username'] != app.config['USERNAME']:
            error = 'Invalid username'
        elif request.form['password'] != app.config['PASSWORD']:
            error = 'Invalid password'
        else:
            session['logged_in'] = True
            flash('You were logged in')
            return redirect(url_for('show_entries'))
            return render_template('login.html', error=error)

错误: 显示没有函数返回值; 原因 : 没有注重格式,将 return 语句写在了上一层作用域内;

3. 'Flask' object has no attribute 'app'

def init_db():
    with app.app.context():
        db = get_db()
        with app.open_resource('schema.sql', mode='r') as f:
            db.cursor().executescript(f.read())
        db.commit()

原因:将app.app_context() 写成了 app.app.context(),所以它没办法识别app;

4 . mac 自带有python 2.7, 但我想用 python 最新版,pyhton3; 用pip也安装不成功;最后实现的方法是:

用 brewbrew 终端,先执行 brew uninstall python ,r然后再执行 brew install python ;

再执行 python,显示出来的就是python3的版本信息了。

5. Error: The file/path provided (flaskr) does not appear to exist. Please verify the path is correct. If app is not on PYTHONPATH, ensure the extension is .py

在做 flask 官网中flask-tutorial 时遇到的问题

` export FLASK_APP=flaskr

export FLASK_ENV=development

flask run `

解决:将 flask run 换成 python -m flask run

综上: 遇到的很多都是拼写问题,一定要注意啊!!!

转载于:https://my.oschina.net/hyzccc/blog/3072813

你可能感兴趣的:(flaskr 遇到的问题)