轻量Pythonweb - flask+jinja2
后台代码 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>
轻量Pythonweb - flask+jinja2的更多相关文章
- 轻量的web框架Bottle
简洁的web框架Bottle 简介 Bottle是一个非常简洁,轻量web框架,与django形成鲜明的对比,它只由一个单文件组成,文件总共只有3700多行代码,依赖只有python标准库.但是麻雀虽 ...
- Raspkate - 基于.NET的可运行于树莓派的轻量型Web服务器
最近在业余时间玩玩树莓派,刚开始的时候在树莓派里写一些基于wiringPi库的C语言程序来控制树莓派的GPIO引脚,从而控制LED发光二极管的闪烁,后来觉得,是不是可以使用HTML5+jQuery等流 ...
- 一种简单,轻量,灵活的C#对象转Json对象的方案
简单,是因为只有一个类 轻量,是因为整个类代码只有300行 灵活,是因为扩展方式只需要继承重写某个方法即可 补充:修正无法处理可空值类型的bug 首先我将这个类称之为JsonBuilder,我希望它以 ...
- 一种简单,轻量,灵活的C#对象转Json对象的方案(续)
本文参考资料 一种简单,轻量,灵活的C#对象转Json对象的方案 [源码]Literacy 快速反射读写对象属性,字段 一段废话 之前我已经介绍了这个方案的名称为JsonBuilder,这套方案最大的 ...
- Dapper.NET——轻量ORM
Dapper.NET使用 http://www.cnblogs.com/yankliu-vip/p/4182892.html 本文目录 Dapper.NET使用 1.为什么选择Dapper 2.以Da ...
- 编写轻量ajax组件01-对比webform平台上的各种实现方式
前言 Asp.net WebForm 和 Asp.net MVC(简称MVC) 都是基于Asp.net的web开发框架,两者有很大的区别,其中一个就是MVC更加注重http本质,而WebForm试图屏 ...
- Vue.js:轻量高效的前端组件化方案
转发一篇尤老师对vue.js的介绍,了解vue.js的来龙去脉.不过现在已经是2.0了,也有添加一些新的东西,当然有些东西也改了. Vue.js:轻量高效的前端组件化方案 Vue.js 是我在2014 ...
- 基于netty轻量的高性能分布式RPC服务框架forest<下篇>
基于netty轻量的高性能分布式RPC服务框架forest<上篇> 文章已经简单介绍了forest的快速入门,本文旨在介绍forest用户指南. 基本介绍 Forest是一套基于java开 ...
- 基于netty轻量的高性能分布式RPC服务框架forest<上篇>
工作几年,用过不不少RPC框架,也算是读过一些RPC源码.之前也撸过几次RPC框架,但是不断的被自己否定,最近终于又撸了一个,希望能够不断迭代出自己喜欢的样子. 顺便也记录一下撸RPC的过程,一来作为 ...
随机推荐
- rocketmq批量消息投递
批量发送消息可提高传递小消息的性能.同时也需要满足以下特征 批量消息要求必要具有同一topic.相同消息配置 不支持延时消息 建议一个批量消息最好不要超过1MB大小 示例 小于1MB String t ...
- cvc-elt.1: Cannot find the declaration of element 'beans'Failed to read schema document 'http://www.springframework.org/schema/beans/spring- beans-3.0.xsd'
Multiple annotations found at this line: - cvc-elt.1: Cannot find the declaration of element 'beans' ...
- FelxCell常用属性设置(未完待续......)
this.grid1.AllowUserPaste//返回或设置是否允许用户粘贴文字和格式 grid1.Cell(Rows, 1).WrapText = true;//设置单元格自动换行
- vue启动时候报错
使用vue时,在已经安装模块完毕的情况下,依旧会报错,如: Module build failed: Error: %1 is not a valid Win32 application. 这个时候只 ...
- npm包--rimraf
含义 rimraf 包的作用:以包的形式包装rm -rf命令,用来删除文件和文件夹的,不管文件夹是否为空,都可删除. 安装 npm install rimraf --save-dev 使用 const ...
- MR-join连接1......
MR-join连接
- echarts实时数据图表
import React, { PureComponent } from 'react'; import ReactEcharts from 'echarts-for-react'; import m ...
- 实验一 windows基本网络命令
一. 实验目的 1. 了解windows系统中网络命令的基本功能. 2. 掌握基本网络命令的使用方法. 3. 掌握使用网络命令观察网络状态的方法. 二.实验环境 1. 软件环境:Microsoft W ...
- Idea在@Autowired注入时报错
Could not autowire. No beans of 'UserDao' type found 如图,是因为idea检测能力太强,一旦没有找到实现类就会报错,但是我试了,这里其实是注入进来了 ...
- Java 写 Log
. 一个最基本的例子 使用Logging框架写Log基本上就三个步骤 引入loggerg类和logger工厂类 声明logger 记录日志 下面看一个例子 //1. 引入slf4j接口的Logger和 ...