我正在使用Meraki Captive Portal API。流程是这样的。
登录代码如下:
def index(request):
# if this is a POST request we need to process the form data
if request.method == 'POST':
username = request.POST['username']
code = request.POST['code']
login_url = request.session['login_url']
continue_url = 'http://' + request.get_host() +
reverse('splash:home')
login_params = {"username": username,
"password": code,
"continue_url": continue_url}
r = requests.post(login_url, params=login_params)
# if a GET (or any other method) we'll create a blank form
else:
login_url = request.GET['login_url']
continue_url = request.GET['continue_url']
ap_name = request.GET['ap_name']
ap_mac = request.GET['ap_mac']
ap_tags = request.GET['ap_tags']
client_ip = request.GET['client_ip']
client_mac = request.GET['client_mac']
request.session['login_url'] = login_url
request.session['continue_url'] = continue_url
request.session['ap_name'] = ap_name
request.session['ap_mac'] = ap_mac
request.session['ap_tags'] = ap_tags
request.session['client_ip'] = client_ip
request.session['client_mac'] = client_mac
return render(request, 'splash/index.html')
问题在这里:
r = requests.post(login_url, params=login_params,
allow_redirects=True)
一切正常。但是,当Meraki API进行GET请求时,不会被重定向。我仍然在登录页面上。我可以对视图做些什么,以允许API进行重定向。
在控制台上,我可以看到正在调用的页面,但浏览器没有显示主页。
[18 / Sep / 2018 14:56:20]“ GET / splash / home / HTTP / 1.1” 200 1234
[18 / Sep / 2018 14:56:20]“ POST / splash / HTTP / 1.1” 200 2333
非常感谢您的帮助。