zoukankan      html  css  js  c++  java
  • 小白flask框架第一个程序(windows平台下python2.7)

    步骤

    一、创建test文件夹

    二、在test文件夹下创建main.py文件和templates文件夹

      main.py代码如下:

      

     1 # -*- condig:utf-8 -*-
     2 
     3 from flask import Flask,render_template,request
     4 
     5 app = Flask(__name__)
     6 
     7 @app.route('/login')
     8 def index():
     9     # return 'hello Flask'
    10     return render_template('login.html')
    11     
    12 @app.route('/test',methods=['POST'])
    13 def success():
    14     if request.method == 'POST':
    15         email = request.form['email']
    16         return render_template('success.html',email=email)
    17     else:
    18         pass
    19     
    20 if __name__ == '__main__':
    21     app.run(
    22         host='0.0.0.0',
    23         port=7777,
    24         debug=True
    25     )
    View Code

    三、在templates文件夹下创建login.html文件和success.html文件

      login.html代码如下:

     1 <<!DOCTYPE html>
     2 <html>
     3 <head>
     4 <meta charset = utf-8>
     5 <title>flask登陆</title>
     6 </head>
     7 <body>
     8 
     9 <h1>Welcome to the Flask web</h1>
    10 <form action='/test' method='post'>
    11     <input type='text' name='email' placeholder='Enter Email Address'>
    12     <br/><br/>
    13     <input type='password' name='pass' placeholder='Passwork'>
    14     <input type='submit' value='Submit' name='ok'>
    15 
    16 </form>
    17 
    18 </body>
    19 </html>
    View Code

      success.html代码如下:

     1 <<!DOCTYPE html>
     2 <html>
     3 <head>
     4 <meta charset = utf-8>
     5 <title>登陆成功</title>
     6 </head>
     7 <body>
     8 
     9 <center><h2>SUCCESSFULLY WITH YOUR EMAIL: {{email}}</h2></center>
    10 
    11 
    12 </body>
    13 </html>
    View Code

    四、在cmd命令行下,切换到test文件夹下运行python2 main.py,

    在浏览器网址输入框内输入127.0.0.1:7777/login则转到登陆页面,

    在登陆页面输入email和password点击submit则转到登陆成功页面。

  • 相关阅读:
    Oracle游标举例
    java程序写的模拟用户点击的程序(抢小米程序)
    最好的ASP.NET MVC入门 step by step 来自微软
    项目经理
    程序员的职场晋升之路
    程序员怎么样才能进入微软?
    浅谈程序员创业
    软件销售心得-送给自己卖软件的程序员
    lamda表达式,匿名函数
    为什么Flash没能在移动设备上挺住?
  • 原文地址:https://www.cnblogs.com/znh8/p/9322517.html
Copyright © 2011-2022 走看看