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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值