zoukankan      html  css  js  c++  java
  • 模版、请求相应

    模版

    '''
    支持函数加括号并且传参
    其它的用法完全同DTL
    模版中处理:{{ ss|safe }}
    视图函数中:ss = Markup(ss)
    如何处理xss攻击
        html中的符号替换成了特殊字符
        Markup或是|safe是把特殊字符重新替换回来
    Markup等价于django的mark_safe
    extends,include一模一样
    '''
    
    from flask import Flask, render_template, Markup
    
    app = Flask(__name__)
    
    
    def func1(args):
        return Markup("<input type='text' value='%s' />" % (args,))
    
    
    @app.route('/')
    def jin_jia():
        return render_template('jin_jia.html', ff=func1)
    
    
    if __name__ == '__main__':
        app.run()
    # html页面中渲染
    {{ ff('xxx') }}
    

    请求响应

    request请求对象
    form,args,methos
    response响应对象
    写cookie,写headers

        from flask import Flask
        from flask import request
        from flask import render_template
        from flask import redirect
        from flask import make_response
    
        app = Flask(__name__)
    
    
        @app.route('/login.html', methods=['GET', "POST"])
        def login():
    
            # 请求相关信息
            # request.method
            # request.args
            # request.form
            # request.values
            # request.cookies
            # request.headers
            # request.path
            # request.full_path
            # request.script_root
            # request.url
            # request.base_url
            # request.url_root
            # request.host_url
            # request.host
            # request.files
            # obj = request.files['the_file_name']
            # obj.save('/var/www/uploads/' + secure_filename(f.filename))
    
            # 响应相关信息
            # return "字符串"
            # return render_template('html模板路径',**{})
            # return redirect('/index.html')
            #return jsonify({'k1':'v1'})
    
            # response = make_response(render_template('index.html'))
            # response是flask.wrappers.Response类型
            # response.delete_cookie('key')
            # response.set_cookie('key', 'value')
            # response.headers['X-Something'] = 'A value'
            # return response
            return "内容"
    
        if __name__ == '__main__':
            app.run()
    
  • 相关阅读:
    Oracle分析函数row_number()等的使用实例
    Oracle行列转换case when then方法案例
    Oracle日期函数
    Oracle转换函数
    Oracle数值函数
    Oracle字符函数length substr concat实例
    Oracle列转行函数LISTAGG()
    Oracle 条件判断函数decode和case when then案例
    Oracle NVL空值处理函数
    【学亮开讲】Oracle内外连接查询20181119
  • 原文地址:https://www.cnblogs.com/ShenJunHui6/p/11219484.html
Copyright © 2011-2022 走看看