Flask学习

2018-11-01  本文已影响9人  LoveLinXue
#该方法在访问地址的时候login后边带不带斜杠它都会自动补全展示信息
@app.route('/login/')
def loginAction():
    return render_template('login.html', title='登录')

#该方法在访问地址的时候login后边不带斜杠可以访问,带上斜杠会访问不到,它不会自动补全展示信息
@app.route('/login')
def loginAction():
    return render_template('login.html', title='登录')
#http://127.0.0.1:5000/regest/
#http://127.0.0.1:5000/login/
#以上两个地址都会指向login.HTML界面
@app.route('/regest/')
@app.route('/login/')
def loginAction():
    return render_template('login.html', title='登录')
@app.route('/project/', methods=["GET", 'POST'])
def project():
    if request.method == 'POST':
        # 如果form表单里没有username这个Key值的话会抛出异常
        username = request.form['username']
        password = request.form['password']
    else:
        # http://127.0.0.1:5000/project/?username=ling
        # 如果前端是用?拼接参数的话,就需要使用args来获取值
        username = request.args['username']
        password = request.args['password']

    return render_template('project.html')
# 404会调用的方法和文件
@app.errorhandler(404)
def page_not_fount(error):
    return render_template('404.html'), 404

关于查找Flask的扩展包

上一篇 下一篇

猜你喜欢

热点阅读