Time to realize the function, access the test page, jump to the registration page, registration is successful jump to the test page
Use parameters: If a jump when coming from a different address, header information will carry parameters referrer, this parameter is the address from which to jump into the current address, if the address is entered directly from the browser, it will not carry this argument
Prepare a test page and interfaces
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<a href="{{ url_for('front.signup') }}">点击注册</a>
</body>
</html>
Check whether the url legal logic
from urllib.parse import urlparse, urljoin
from flask import request
def is_safe_url(target):
""" 判断url是否合法,是否在同一域名 """
ref_url = urlparse(request.host_url)
test_url = urlparse(urljoin(request.host_url, target))
return test_url.scheme in ('http', 'https') and ref_url.netloc == test_url.netloc
get请求里面判断,和是否加入referrer参数
def get(self):
referrer = request.referrer # 来到此接口的上一个接口
if referrer and referrer != request.url and safeutils.is_safe_url(referrer):
return render_template('front/front_signup.html', referrer=referrer)
else:
return render_template('front/front_signup.html')
模板中加入此参数,并隐藏
js在成功的回调函数中判断
跳转注册: