zoukankan      html  css  js  c++  java
  • 轻量Pythonweb

    后台代码 MVC

    from flask import Flask,request,render_template
    
    app = Flask(__name__)
    
    @app.route('/',methods=['GET','POST'])
    def home():
        return render_template('home.html')
    
    @app.route('/signin',methods=['GET'])
    def signin_form():
        return render_template('form.html')
    
    @app.route('/signin',methods=['POST'])
    def sigin():
        username = request.form['username']
        password = request.form['password']
        if username.strip() == 'admin' and password.strip() == 'password':
            return render_template('signin-ok.html',username=username)
        return render_template('form.html',message='Bad information...',username=username)
    
    if __name__ == '__main__':
        app.run()
    

    View 都放到 templates 目录下

    <html>
    <head>
      <title>Home</title>
    </head>
    <body>
      <h1 style="font-style:italic">Home</h1>
    </body>
    </html>
    
    <html>
    <head>
      <title>Please Sign In</title>
    </head>
    <body>
      {% if message %}
      <p style="color:red">{{ message }}</p>
      {% endif %}
      <form action="/signin" method="post">
        <legend>Please sign in:</legend>
        <p><input name="username" placeholder="Username" value="{{ username }}"></p>
        <p><input name="password" placeholder="Password" type="password"></p>
        <p><button type="submit">Sign In</button></p>
      </form>
    </body>
    </html>
    
    <html>
    <head>
      <title>Welcome, {{ username }}</title>
    </head>
    <body>
      <p>Welcome, {{ username }}!</p>
    </body>
    </html>
    
    如果有来生,一个人去远行,看不同的风景,感受生命的活力。。。
  • 相关阅读:
    Qt QPainter::end: Painter ended whith 2 saced states
    2月6日学习内容
    2月5日学习总结
    2月4日所学内容
    2月3日学习内容
    2月2日学习收获
    2月1日学习内容
    构建之法读后感(一)
    11月从小工到专家读后感(二)
    11月从小工到专家的读后感(一)
  • 原文地址:https://www.cnblogs.com/Frank99/p/10551483.html
Copyright © 2011-2022 走看看