MarkdownPad Document

*:first-child {
margin-top: 0 !important;
}

body>*:last-child {
margin-bottom: 0 !important;
}

/* BLOCKS
=============================================================================*/

p, blockquote, ul, ol, dl, table, pre {
margin: 15px 0;
}

/* HEADERS
=============================================================================*/

h1, h2, h3, h4, h5, h6 {
margin: 20px 0 10px;
padding: 0;
font-weight: bold;
-webkit-font-smoothing: antialiased;
}

h1 tt, h1 code, h2 tt, h2 code, h3 tt, h3 code, h4 tt, h4 code, h5 tt, h5 code, h6 tt, h6 code {
font-size: inherit;
}

h1 {
font-size: 28px;
color: #000;
}

h2 {
font-size: 24px;
border-bottom: 1px solid #ccc;
color: #000;
}

h3 {
font-size: 18px;
}

h4 {
font-size: 16px;
}

h5 {
font-size: 14px;
}

h6 {
color: #777;
font-size: 14px;
}

body>h2:first-child, body>h1:first-child, body>h1:first-child+h2, body>h3:first-child, body>h4:first-child, body>h5:first-child, body>h6:first-child {
margin-top: 0;
padding-top: 0;
}

a:first-child h1, a:first-child h2, a:first-child h3, a:first-child h4, a:first-child h5, a:first-child h6 {
margin-top: 0;
padding-top: 0;
}

h1+p, h2+p, h3+p, h4+p, h5+p, h6+p {
margin-top: 10px;
}

/* LINKS
=============================================================================*/

a {
color: #4183C4;
text-decoration: none;
}

a:hover {
text-decoration: underline;
}

/* LISTS
=============================================================================*/

ul, ol {
padding-left: 30px;
}

ul li > :first-child,
ol li > :first-child,
ul li ul:first-of-type,
ol li ol:first-of-type,
ul li ol:first-of-type,
ol li ul:first-of-type {
margin-top: 0px;
}

ul ul, ul ol, ol ol, ol ul {
margin-bottom: 0;
}

dl {
padding: 0;
}

dl dt {
font-size: 14px;
font-weight: bold;
font-style: italic;
padding: 0;
margin: 15px 0 5px;
}

dl dt:first-child {
padding: 0;
}

dl dt>:first-child {
margin-top: 0px;
}

dl dt>:last-child {
margin-bottom: 0px;
}

dl dd {
margin: 0 0 15px;
padding: 0 15px;
}

dl dd>:first-child {
margin-top: 0px;
}

dl dd>:last-child {
margin-bottom: 0px;
}

/* CODE
=============================================================================*/

pre, code, tt {
font-size: 12px;
font-family: Consolas, "Liberation Mono", Courier, monospace;
}

code, tt {
margin: 0 0px;
padding: 0px 0px;
white-space: nowrap;
border: 1px solid #eaeaea;
background-color: #f8f8f8;
border-radius: 3px;
}

pre>code {
margin: 0;
padding: 0;
white-space: pre;
border: none;
background: transparent;
}

pre {
background-color: #f8f8f8;
border: 1px solid #ccc;
font-size: 13px;
line-height: 19px;
overflow: auto;
padding: 6px 10px;
border-radius: 3px;
}

pre code, pre tt {
background-color: transparent;
border: none;
}

kbd {
-moz-border-bottom-colors: none;
-moz-border-left-colors: none;
-moz-border-right-colors: none;
-moz-border-top-colors: none;
background-color: #DDDDDD;
background-image: linear-gradient(#F1F1F1, #DDDDDD);
background-repeat: repeat-x;
border-color: #DDDDDD #CCCCCC #CCCCCC #DDDDDD;
border-image: none;
border-radius: 2px 2px 2px 2px;
border-style: solid;
border-width: 1px;
font-family: "Helvetica Neue",Helvetica,Arial,sans-serif;
line-height: 10px;
padding: 1px 4px;
}

/* QUOTES
=============================================================================*/

blockquote {
border-left: 4px solid #DDD;
padding: 0 15px;
color: #777;
}

blockquote>:first-child {
margin-top: 0px;
}

blockquote>:last-child {
margin-bottom: 0px;
}

/* HORIZONTAL RULES
=============================================================================*/

hr {
clear: both;
margin: 15px 0;
height: 0px;
overflow: hidden;
border: none;
background: transparent;
border-bottom: 4px solid #ddd;
padding: 0;
}

/* TABLES
=============================================================================*/

table th {
font-weight: bold;
}

table th, table td {
border: 1px solid #ccc;
padding: 6px 13px;
}

table tr {
border-top: 1px solid #ccc;
background-color: #fff;
}

table tr:nth-child(2n) {
background-color: #f8f8f8;
}

/* IMAGES
=============================================================================*/

img {
max-width: 100%
}
-->

python Flask教程

例子1:

import flask
from flask import *
app=Flask(__name__) #创建新的开始 @app.route('/') #路由设置
def imdex(): #如果访问了/则调用下面的局部变量
return 'Post qingqiu !' #输出 if __name__ == '__main__':
app.run() #运行开始

访问:127.0.0.1:5000/
结果:

请求方式

例子2:

import flask
from flask import *
app=Flask(__name__)
#flask.request为请求方式
@app.route('/',methods=['GET',"POST"]) #mthods定义了请求的方式
def imdex():
if request.method=='POST': #判断请求
return 'Post qingqiu !'
else:
return 'Get qinqiu !' if __name__ == '__main__':
app.run()

GET请求返回的结果如下:

POST请求如下:

模板渲染

在同一目录下创建一个templates的文件夹,然后里面放入你要调用
的html。使用render_template('要调用的html')
例子3:

import flask
from flask import *
app=Flask(__name__) @app.route('/',methods=['GET',"POST"])
def imdex():
if request.method=='POST':
return 'Post qingqiu !'
else:
return render_template('index.html') #调用html if __name__ == '__main__':
app.run()

index.html代码:

    <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>小灰灰的网络博客</title>
</head>
<body>
<h1>Hello Word</h1>
</body>
</html>

结果:

动态摸版渲染

个人来认为吧,这个应该比较少用到,毕竟是这样子的:/路径/参数
例子:

import flask
from flask import *
app=Flask(__name__) @app.route('/index')
@app.route('/index/<name>') #html里面的参数为name这里也为name动态摸版调用
def index(name): #html里面的参数为name这里也为name
return render_template('index.html',name=name) #调用 if __name__ == '__main__':
app.run()

html代码:

    <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>小灰灰的网络博客</title>
</head>
<body>
<h1>Hello {{name}}!</h1>
</body>
</html>

结果:

接受请求参数

例子:
request.form.请求方式('表单里的数据名称') #用于接受表单传来的数据

import flask
from flask import *
app=Flask(__name__) @app.route('/index/<name>')
def index(name):
return render_template('index.html',name=name) @app.route('/login',methods=['GET','POST']) #可使用的请求有GET和POST
def login():
error=None
if request.method=="GET": #如果请求为GET打开login.html
return render_template('login.html')
else:
username=request.form.get('username') #获取表单里的username数据
password=request.form.get('password') #获取表单里的password数据
if username=='admin' and password=='admin': #判断表单里的username和password数据是否等于admin
return 'login ok' #如果是则返回登录成功 if __name__ == '__main__':
app.run()

html代码:
这里的{{ url_for('login') }} #代表着发送数据

    <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Login</title>
</head>
<body>
<form action="{{url_for('login')}}" method="POST">
<input type="text" name="username">
<input type="password" name="password">
<input type="submit" value="login">
</form>
</body>
</html>

结果如下

输入admin admin
返回如下

python Flask篇(一)的更多相关文章

  1. #3使用html+css+js制作网页 番外篇 使用python flask 框架 (II)

    #3使用html+css+js制作网页 番外篇 使用python flask 框架 II第二部 0. 本系列教程 1. 登录功能准备 a.python中操控mysql b. 安装数据库 c.安装mys ...

  2. #3使用html+css+js制作网页 番外篇 使用python flask 框架 (I)

    #3使用html+css+js制作网页 番外篇 使用python flask 框架(I 第一部) 0. 本系列教程 1. 准备 a.python b. flask c. flask 环境安装 d. f ...

  3. 【Python五篇慢慢弹】快速上手学python

    快速上手学python 作者:白宁超 2016年10月4日19:59:39 摘要:python语言俨然不算新技术,七八年前甚至更早已有很多人研习,只是没有现在流行罢了.之所以当下如此盛行,我想肯定是多 ...

  4. [Python][flask][flask-login]关于flask-login中各种API使用实例

    本篇博文跟上一篇[Python][flask][flask-wtf]关于flask-wtf中API使用实例教程有莫大的关系. 简介:Flask-Login 为 Flask 提供了用户会话管理.它处理了 ...

  5. 细数Python Flask微信公众号开发中遇到的那些坑

    最近两三个月的时间,断断续续边学边做完成了一个微信公众号页面的开发工作.这是一个快递系统,主要功能有用户管理.寄收件地址管理.用户下单,订单管理,订单查询及一些宣传页面等.本文主要细数下开发过程中遇到 ...

  6. 使用Nginx+Uwsgi部署Python Flask项目

    第一次用Flask做Web(也是第一次用Python做Web),在部署的时候遇到了不少问题,现在将过程就下来,供在这方面也有疑惑的人参考.(PS:使用Apache+mod_wsgi部署模式的可以参考另 ...

  7. 前端和后端的数据交互(jquery ajax+python flask+mysql)

    上web课的时候老师布置的一个实验,要求省市连动,基本要求如下: 1.用select选中一个省份. 2.省份数据传送到服务器,服务器从数据库中搜索对应城市信息. 3.将城市信息返回客户,客户用sele ...

  8. 知了课堂 Python Flask零基础 笔记整理

    目录 起步 安装Python2.7: Python虚拟环境介绍与安装: pip安装flask: 认识url: URL详解 web服务器和应用服务器以及web应用框架: Flask 第一个flask程序 ...

  9. Python+Flask+Gunicorn 项目实战(一) 从零开始,写一个Markdown解析器 —— 初体验

    (一)前言 在开始学习之前,你需要确保你对Python, JavaScript, HTML, Markdown语法有非常基础的了解.项目的源码你可以在 https://github.com/zhu-y ...

随机推荐

  1. Java回顾之多线程同步

    在这篇文章里,我们关注线程同步的话题.这是比多线程更复杂,稍不留意,我们就会“掉到坑里”,而且和单线程程序不同,多线程的错误是否每次都出现,也是不固定的,这给调试也带来了很大的挑战. 在这篇文章里,我 ...

  2. MQ是什么 RabbitMQ

    一.rabbitMQ是什么: RabbitMQ,遵循AMQP协议,由内在高并发的erlanng语言开发,用在实时的对可靠性要求比较高的消息传递上. 学过websocket的来理解rabbitMQ应该是 ...

  3. JSP 语法

    JSP 语法 本小节将会简单地介绍一下JSP开发中的基础语法. 脚本程序 脚本程序可以包含任意量的Java语句.变量.方法或表达式,只要它们在脚本语言中是有效的. 脚本程序的语法格式: <% 代 ...

  4. 【Scipy】初步认识

    Scipy扩展包括多种多样的工具箱,这些工具致力于解决科学计算中的常见问题.不同的子模块对应不同的应用,比如插值, 整合, 优化, 图像处理, 统计, 特殊功能等等. scipy可以和其他的标准科学计 ...

  5. sgu 137. Funny Strings 线性同余,数论,构造 难度:3

    137. Funny Strings time limit per test: 0.25 sec. memory limit per test: 4096 KB Let's consider a st ...

  6. halcon之屌炸天的自标定(1)

      本次先对halcon的自标定做个整体介绍,了解屌炸天的自标定在实际应用中的应用与实现方法,具体的编程细节将在后续的文章中介绍. halcon提供了一种自标定的算子,它可以在不用标定板的情况下,标定 ...

  7. myeclipse单步调试

    如何进行myclipse的单步调式与跟踪?希望大虾们详细点,多谢. 打断点,然后运行,进debug试图,按F6执行一行,按F5是钻进去执行 追问 朋友,能详细点吗? 本人是初学 回答 如图 如若成功请 ...

  8. Django 之 自定义中间件

    环境:django:1.10    python: 2.7 简介 中间件是一个轻量级.底层的插件系统,可以介入 django 的请求和响应处理过程,修改 django 的输入和输出. 在 django ...

  9. IOS [转]setValue和setObject的区别

    在使用NSMutableDictionary的时候经常会使用setValue forKey与setObject forKey,他们经常是可以交互使用的,代码中经常每一种的使用都有. 1,先看看setV ...

  10. 用 Python 快速实现 HTTP 和 FTP 服务器

      用 Python 快速实现 HTTP 服务器 有时你需临时搭建一个简单的 Web Server,但你又不想去安装 Apache.Nginx 等这类功能较复杂的 HTTP 服务程序时.这时可以使用  ...