分类: 未分类

  • 使用flask生成数据接口API-python

    #-*- coding:utf-8 -*-
    from flask import Flask, request, jsonify
    from werkzeug.utils import redirect
    app = Flask(__name__)
    
    #数据显示支持中文
    app.config['JSON_AS_ASCII'] = False
    
    
    @app.route("/")
    def hello_world():
        return "hello world"
    
    @app.route("/hey/<username>/")
    def hey_yingyong(username):
        return "hey %s" % username
    
    @app.route("/my_number/<int:number>/")
    def my_number(number):
        return "my %s" % (number+number)
    
    @app.route("/my_float/<float:number>/")
    def my_float(number): return "my %s" % (number+number)
    
    @app.route("/baidu/")
    def baidu():
        return redirect("http://www.baidu.com")
    
    @app.route("/json")
    def json():
        dict = [{"name":'张三'}, {"gender":'男'}]
        return jsonify(dict)
    
    # 默认是get,可以改为post
    @app.route("/p", methods=["GET"])
    def he():
        return "hello_world"
    
    # 处理get和post请求
    @app.route("/test/my/first", methods=["POST"])
    def first_post():
        try:
            my_json = request.get_json()
            print(my_json)
            get_name = my_json.get("name")
            get_age = my_json.get("age")
            if not all([get_name,get_age]):
                return jsonify(msg="缺少参数")
    
            get_age += 10
            return jsonify(name=get_name, age=get_age)
        except Exception as e:
            print(e)
            return jsonify(msg="出错了哦,请查看是否正确访问")
    
    
    app.run(host="0.0.0.0")

     

  • Vue-for循环

     

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8">
    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
    <title>文档标题</title>
    </head>
    <body>
      <div id="app">
        <h1>
          {{ message }}
        </h1>
        <p v-for="(name,i) in list">
          网站名称:{{ name.name }} | 网址:{{ name.url }} | 网站备注:{{ name.note }} | 索引:{{ i }}
        </p>
      </div>
    </body>
      <script>
        var app = new Vue({
        el: '#app',
        data: {
          message: '网址导航',
          list1:[1,2,3,4],
          list:[
           { name: '1',url: '2',note: '3' },
           { name: '1',url: '2',note: '3' },
          ],
        }
      })
      </script>
    </html>
    

     

  • 我做了一个网站

    我做了一个网站,但是我不知道放什么内容。

    屑!