zoukankan      html  css  js  c++  java
  • flask快速入门

    from flask import Flask,url_for, render_template
    from flask import request, redirect
    
    app = Flask(__name__)
    
    # 路由
    @app.route('/')
    def index():
        return 'Index Page'
    
    # @app.route('/hello')
    # def hello():
    #     return 'Hello World'
    
    # 变量规则
    @app.route('/user/<username>')
    def show_user(username):
        return 'User %s' % username
    
    # url重定向
    @app.route('/project/')
    def project():
        return 'project'
    
    @app.route('/about')
    def about():
        return 'about'
    
    
    # http方法
    # @app.route('/login', methods=['GET', 'POST'])
    # def login():
    #     if request.method == 'POST':
    #         return 'do the login'
    #     else:
    #         return 'show the login form'
    
    # 模板渲染
    @app.route('/hello/<name>')
    def hello(name):
        return render_template('hello.html', name=name)
    
    
    # 请求对象
    @app.route('/login', methods=['GET', 'POST'])
    def login():
        if request.method == 'POST':
            username = request.form['username']
            password = request.form['password']
        else:
            return render_template('login.html')
    
    # 文件上传
    @app.route('/upload', methods=['GET', 'POST'])
    def upload_file():
        if request.method == 'POST':
            file_name = request.form['filename']
            f = request.files['the_file']
            f.save('/home/zhangjian/PycharmProjects/js逆向/app/file/{}'.format(file_name))
            return render_template('upload.html')
        else:
            return render_template('upload.html')
    
    
    # 重定向和错误
    @app.route('/bbs')
    def bbs():
        return redirect(url_for('upload_file'))
    
    if __name__ == '__main__':
        app.run('127.0.0.1',5000)
  • 相关阅读:
    [转载]RTSP in Stagefright
    FFMPEG for WMA Build Script
    Merge AACExtractor from ICS to Froyo
    查看部署在Heroku上的项目信息
    About AudioSystem Mute
    C++标准转换运算符reinterpret_cast
    纯CSS动态效果的画廊
    基于正则表达式匹配的C++语法高亮度显示
    C++标准转换运算符static_cast
    C++标准转换运算符const_cast
  • 原文地址:https://www.cnblogs.com/zhangjian0092/p/12255204.html
Copyright © 2011-2022 走看看