- 浏览: 383042 次
- 性别:
- 来自: 四川
-
文章分类
- 全部博客 (247)
- 数据库以及sql (11)
- java (48)
- 爬虫学习 (20)
- java编程 (28)
- python编程以及安装和配置 (27)
- oracle数据库 (32)
- mongodb基本操作 (4)
- linux学习 (7)
- easyUI (2)
- nodeJs (8)
- python学习 (16)
- 其他 (13)
- hadoop (1)
- svn (1)
- 汉字 (1)
- windows (2)
- jsp (5)
- fiddler (1)
- ETL (1)
- teamviewer (1)
- maven (4)
- GIT (2)
- datagrip (1)
- ocr (1)
- redis (3)
- mysql (3)
- linux (1)
- 数据服务 (0)
最新评论
=======================get请求
# coding=utf-8
'''
Created on 2017年5月9日
@author: chenkai
'''
import bottle
def check_login(username, password):
if username == 'kaige' and password == '123456':
return True
else:
return False
@bottle.route('/login')
def login():
if bottle.request.GET.get('do_submit','').strip(): #点击登录按钮
# 第一种方式(latin1编码)
## username = bottle.request.GET.get('username','').strip() # 用户名
## password = bottle.request.GET.get('password','').strip() # 密码
#第二种方式(获取username\password)(latin1编码)
getValue = bottle.request.query_string
## username = bottle.request.query['username'] # An utf8 string provisionally decoded as ISO-8859-1 by the server
## password = bottle.request.query['password'] # 注:ISO-8859-1(即aka latin1编码)
#第三种方式(获取UTF-8编码)
username = bottle.request.query.username # The same string correctly re-encoded as utf8 by bottle
password = bottle.request.query.password # The same string correctly re-encoded as utf8 by bottle
if check_login(username, password):
return "<p>登录成功</p>"
else:
return "<p>登陆失败,用户名或者密码错误</p>"
else:
return ''' <form action="/login" method="get">
Username: <input name="username" type="text" />
Password: <input name="password" type="password" />
<input value="Login" name="do_submit" type="submit">
</form>
'''
bottle.run(host='localhost', port=8083)
运行这个py程序后,浏览器输入:http://localhost:8083/login , 输入用户名和密码,点击登录
===================================post请求
# coding=utf-8
'''
Created on 2017年5月9日
@author: chenkai
'''
import bottle
def check_login(username, password):
if username == 'kaige' and password == '123456':
return True
else:
return False
@bottle.route('/login')
def login():
return ''' <form action="/login" method="post">
Username: <input name="username" type="text" />
Password: <input name="password" type="password" />
<input value="Login" type="submit">
</form>
'''
@bottle.route('/login', method='POST')
def do_login():
# 第一种方式
# username = request.forms.get('username')
# password = request.forms.get('password')
#第二种方式
postValue = bottle.request.POST.decode('utf-8')
username = bottle.request.POST.get('username')
password = bottle.request.POST.get('password')
if check_login(username, password):
return "<p> 登录成功</p>"
else:
return "<p> 登录失败 </p>"
bottle.run(host='localhost', port=8083)
运行这个py程序后,浏览器输入:http://localhost:8083/login , 输入用户名和密码,点击登录,这个明显是post请求, 而且浏览器不会显示参数
# coding=utf-8
'''
Created on 2017年5月9日
@author: chenkai
'''
import bottle
def check_login(username, password):
if username == 'kaige' and password == '123456':
return True
else:
return False
@bottle.route('/login')
def login():
if bottle.request.GET.get('do_submit','').strip(): #点击登录按钮
# 第一种方式(latin1编码)
## username = bottle.request.GET.get('username','').strip() # 用户名
## password = bottle.request.GET.get('password','').strip() # 密码
#第二种方式(获取username\password)(latin1编码)
getValue = bottle.request.query_string
## username = bottle.request.query['username'] # An utf8 string provisionally decoded as ISO-8859-1 by the server
## password = bottle.request.query['password'] # 注:ISO-8859-1(即aka latin1编码)
#第三种方式(获取UTF-8编码)
username = bottle.request.query.username # The same string correctly re-encoded as utf8 by bottle
password = bottle.request.query.password # The same string correctly re-encoded as utf8 by bottle
if check_login(username, password):
return "<p>登录成功</p>"
else:
return "<p>登陆失败,用户名或者密码错误</p>"
else:
return ''' <form action="/login" method="get">
Username: <input name="username" type="text" />
Password: <input name="password" type="password" />
<input value="Login" name="do_submit" type="submit">
</form>
'''
bottle.run(host='localhost', port=8083)
运行这个py程序后,浏览器输入:http://localhost:8083/login , 输入用户名和密码,点击登录
===================================post请求
# coding=utf-8
'''
Created on 2017年5月9日
@author: chenkai
'''
import bottle
def check_login(username, password):
if username == 'kaige' and password == '123456':
return True
else:
return False
@bottle.route('/login')
def login():
return ''' <form action="/login" method="post">
Username: <input name="username" type="text" />
Password: <input name="password" type="password" />
<input value="Login" type="submit">
</form>
'''
@bottle.route('/login', method='POST')
def do_login():
# 第一种方式
# username = request.forms.get('username')
# password = request.forms.get('password')
#第二种方式
postValue = bottle.request.POST.decode('utf-8')
username = bottle.request.POST.get('username')
password = bottle.request.POST.get('password')
if check_login(username, password):
return "<p> 登录成功</p>"
else:
return "<p> 登录失败 </p>"
bottle.run(host='localhost', port=8083)
运行这个py程序后,浏览器输入:http://localhost:8083/login , 输入用户名和密码,点击登录,这个明显是post请求, 而且浏览器不会显示参数
发表评论
-
Pycharm常用快捷键
2018-10-17 16:45 872pycharm常用快捷键 1、编辑(Editing) Ctr ... -
python连接oracle数据库报错PI-1047: 64-bit Oracle Client library cannot be loaded: "解决方案
2018-10-17 16:44 7285错误原因:instantclient版本为32位,需更换成64 ... -
pycharm安装第三方库的方式
2018-10-16 17:33 21981.点击settings之后再点击project下面的proj ... -
pycharm中配置中文头, 不用每次都写
2018-10-16 17:20 1923打开file->settings->Editor- ... -
python 中__name__ = '__main__' 的作用
2018-09-14 09:50 1734出自:https://www.cnblogs.com/alan ... -
python中的textblob库的作用说明
2018-09-14 09:40 3938TextBlob 是一款 Pythonic 的文本处理工具,用 ... -
python 利用bottle微服务提供post接口,供第三方调用
2018-09-12 16:11 1218=============================== ... -
python中的请求参数乱码 解决
2018-09-12 15:39 1354import urllib def geturltoutf8 ... -
python 安装nltk
2018-09-07 18:02 34061、在cmd窗口中,进入到python的文件夹内的 Scrip ... -
python 情感分析
2018-09-07 17:05 1708转:https://blog.csdn.net/u011001 ... -
python结巴分词
2018-03-20 14:46 634# coding=utf-8 ''' Created on 2 ... -
anaconda安装与配置环境变量,以及anaconda是什么,有什么用。
2017-07-12 10:15 10712anaconda安装与配置环境变量: 官网:https://w ... -
python中利用adb shell 控制手机,完美解决中文输入问题
2017-06-03 10:25 54431.连接手机, 打开开发者选项, 连接USB, (如果需要记录 ... -
selenium设置网页文本框中文值报错解决方法
2017-03-20 10:06 1062selenium设置网页文本框中文值报错解决方法 elem = ... -
python多进程和多线程的区别
2017-03-14 17:33 1184多线程和多进程最大的 ...
相关推荐
### Python教程之Bottle Web开发 #### Bottle框架简介 Bottle是一个用Python编写的轻量级Web应用框架,因其简洁高效的特点,在小型项目或快速原型开发中被广泛使用。本教程将详细介绍如何使用Bottle框架进行Web...
Bottle通过`route`装饰器来定义路由规则,允许我们将HTTP请求方法(如GET、POST等)与特定的处理函数关联。例如: ```python from bottle import route, run @route('/hello/:name') def hello(name): return '...
《深入解析Bottle框架:构建高效微型Web应用》 Bottle框架是一款轻量级的Python Web框架,以其简洁、...通过深入理解Bottle的架构和核心功能,开发者可以快速构建出符合需求的Web服务,同时享受到Python的简洁之美。
### Python技术的Web框架与RESTful API开发指南 #### Python Web框架概述 随着互联网技术的不断进步和发展,Web应用开发已成为IT行业中一个重要的分支。Python作为一种语法简洁、功能强大且易于学习的语言,在Web...
Bottle框架的核心特性之一就是它的路由系统,通过`@route`装饰器将URL映射到处理函数。然而,在实际操作中,开发者可能会遇到路由无法识别的情况。例如,尝试添加一个表单登录验证路由: ```python @route('/login'...
1. **Flask基本用法**:如何初始化Flask应用,定义路由,以及如何处理GET和POST请求。 2. **模板引擎**:使用Jinja2(Flask默认的模板引擎)如何创建动态HTML页面。 3. **表单处理**:如何创建HTML表单,以及使用...
这个项目采用Bottle框架,一个轻量级的Python Web服务器和框架,用于快速开发简单的但功能完整的Web应用。让我们深入探讨这个项目涉及的核心知识点。 1. **Bottle框架**: Bottle是一个微型的、单一文件的Web框架...