python flask框架实现重定向功能示例
作者:zhaoyangjian724 时间:2022-01-16 07:14:51
本文实例讲述了python flask框架实现重定向功能。分享给大家供大家参考,具体如下:
flask 重定向:
from flask import *
app = Flask(__name__)
@app.route('/')
def index():
return redirect(url_for('login'))
@app.route('/login')
def login():
return render_template('login.html')
if __name__ == '__main__':
app.run(host='0.0.0.0',port=6001,debug=True)
[oracle@node01 ~]$ curl 192.168.137.1:6001
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>Redirecting...</title>
<h1>Redirecting...</h1>
<p>You should be redirected automatically to target URL: <a href="/login" rel="external nofollow" rel="external nofollow" >/login</a>. If not click the link.[oracle@node01 ~]$
use Net::SMTP;
use LWP::UserAgent;
use HTTP::Cookies;
use HTTP::Headers;
use HTTP::Response;
use Encode;
use Switch;
use File::Temp qw/tempfile/;
use HTTP::Date qw(time2iso str2time time2iso time2isoz);
use Data::Dumper;
my $CurrTime = time2iso(time());
my $ua = LWP::UserAgent->new;
$ua->timeout(10);
$ua->env_proxy;
my $now = time();
$ua->agent('Mozilla/5.0');
my $cookie_jar = HTTP::Cookies->new(
file => 'lwp_cookies.txt',
autosave => 1,
ignore_discard => 1
);
$ua->cookie_jar($cookie_jar);
my $response = $ua->get("http://127.0.0.1:6001/");
if ($response->is_success) {
print encode("gbk",decode("utf8",Dumper($response)));
$r=$response->content;
$str=encode("gbk",decode("utf8","$r"));
print $str."\n";
}
perl 演示:
C:\Users\TLCB\Desktop\python\模块\flask>perl a1.pl
$VAR1 = bless( {
'_protocol' => 'HTTP/1.0',
'_content' => '这是登陆页面',
'_rc' => 200,
'_headers' => bless( {
'client-date' => 'Fri, 01 Sep 2017 03:23:34 GMT',
'content-type' => 'text/html; charset=utf-8',
'client-response-num' => 1,
'date' => 'Fri, 01 Sep 2017 03:23:34 GMT',
'client-peer' => '127.0.0.1:6001',
'server' => 'Werkzeug/0.12.2 Python/2.7.10',
'content-length' => '18'
}, 'HTTP::Headers' ),
'_previous' => bless( {
'_protocol' => 'HTTP/1.0',
'_content' => '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>Redirecting...</title>
<h1>Redirecting...</h1>
<p>You should be redirected automatically to target URL: <a href="/login" rel="external nofollow" rel="external nofollow" >/login</a>. If not click the link.',
'_rc' => '302',
'_headers' => bless( {
'client-response-num' => 1,
'location' => 'http://127.0.0.1:6001/login',
'date' => 'Fri, 01 Sep 2017 03:23:34 GMT',
'client-peer' => '127.0.0.1:6001',
'content-length' => '219',
'client-date' => 'Fri, 01 Sep 2017 03:23:34 GMT',
'content-type' => 'text/html; charset=utf-8',
'server' => 'Werkzeug/0.12.2 Python/2.7.10',
'title' => 'Redirecting...'
}, 'HTTP::Headers' ),
'_msg' => 'FOUND',
'_request' => bless( {
'_content' => '',
'_uri' => bless( do{\(my $o = 'http://127.0.0.1:6001/')}, 'U
'_headers' => bless( {
'user-agent' => 'Mozilla/5.0'
}, 'HTTP::Headers' ),
'_method' => 'GET',
'_uri_canonical' => $VAR1->{'_previous'}{'_request'}{'_uri'}
}, 'HTTP::Request' )
}, 'HTTP::Response' ),
'_msg' => 'OK',
'_request' => bless( {
'_protocol' => undef,
'_content' => '',
'_uri' => bless( do{\(my $o = 'http://127.0.0.1:6001/login')}, 'URI::http' ),
'_headers' => bless( {
'user-agent' => 'Mozilla/5.0'
}, 'HTTP::Headers' ),
'_method' => 'GET',
'_uri_canonical' => $VAR1->{'_request'}{'_uri'}
}, 'HTTP::Request' )
}, 'HTTP::Response' );
这是登陆页面
C:\Users\TLCB\Desktop\python\模块\flask>
希望本文所述对大家基于Flask框架的Python程序设计有所帮助。
来源:https://blog.csdn.net/zhaoyangjian724/article/details/77770969
标签:python,flask,重定向
0
投稿
猜你喜欢
Python实现简单的文本相似度分析操作详解
2023-07-18 11:16:12
Python getattr()函数使用方法代码实例
2022-03-04 03:30:51
解决python3 pika之连接断开的问题
2021-09-28 18:40:09
全网最细 Python 格式化输出用法讲解(推荐)
2021-07-15 12:01:32
python Selenium等待元素出现的具体方法
2022-02-22 02:47:20
我的css样式写法总结
2009-01-18 13:04:00
python中利用h5py模块读取h5文件中的主键方法
2022-07-26 12:02:36
Python中的XML库4Suite Server的介绍
2023-08-12 01:26:41
Python的爬虫程序编写框架Scrapy入门学习教程
2021-12-27 10:01:48
css特性:空白外边距互相叠加
2010-06-21 10:53:00
Golang正整数指定规则排序算法问题分析
2023-07-12 09:12:03
讲解SQL Server危险扩展存储删除和恢复
2008-12-09 14:30:00
Python趣味挑战之turtle库绘画飘落的银杏树
2023-07-21 21:46:40
Tag的自定义类
2010-03-18 15:53:00
asp全面解析Server对象
2008-10-19 17:24:00
Python3 pyecharts生成Html文件柱状图及折线图代码实例
2022-03-17 01:01:46
Python Pygame制作雪夜烟花景
2023-10-21 08:57:07
Go语言Grpc Stream的实现
2023-08-07 06:19:23
MYSQL教程:服务器优化和硬件优化
2009-02-27 15:43:00
python匿名函数的使用方法解析
2022-05-08 13:00:25