如何解决在模板中将上下文从Django视图传递到Modal
views.py中包含以下内容。
def IPSEC_ANA(request):
results = ''
ipsec = IPSEC.objects.all()
remote_conn_pre = paramiko.SSHClient()
remote_conn_pre.set_missing_host_key_policy(paramiko.AutoAddPolicy())
remote_conn_pre.connect(hostname='41.86.xx.xx',port=22,username='root',password='xxxxxxx',look_for_keys=False,allow_agent=False)
remote_conn = remote_conn_pre.invoke_shell()
remote_conn.send('\n')
remote_conn.send('en\n')
remote_conn.send(str(password)+ '\n')
remote_conn.send('sh run | i access-list ' + acl + '\n')
remote_conn.send('\n')
time.sleep(1)
policy = remote_conn.recv(11111111)
time.sleep(1)
remote_conn.send('end\n')
for line in policy.decode('utf-8').split('\r\n'):
if 'access-list ' + acl + ' extended' in line:
results = line
print (results)
context20 = {
'ipsec': ipsec,'results': results,}
template = loader.get_template('ipsecs.html')
return HttpResponse(template.render(context20,request))
def ipsecacl(request):
if request.method == 'GET':
acl = request.GET.get('acl')
remote_conn_pre = paramiko.SSHClient()
remote_conn_pre.set_missing_host_key_policy(paramiko.AutoAddPolicy())
remote_conn_pre.connect(hostname='41.86.xx.xx',password='xxxxxxxx',allow_agent=False)
remote_conn = remote_conn_pre.invoke_shell()
remote_conn.send('\n')
remote_conn.send('en\n')
remote_conn.send(str(password)+ '\n')
remote_conn.send('sh run | i access-list ' + acl + '\n')
remote_conn.send('\n')
time.sleep(1)
policy = remote_conn.recv(11111111)
time.sleep(1)
remote_conn.send('end\n')
for line in policy.decode('utf-8').split('\r\n'):
if 'access-list ' + acl + ' extended' in line:
results = line
print (results)
return render(request,{'results': results},'ipsecs.html')
这是我的html:
{% extends "layouts/base-site.html" %}
{% block content %}
<main class="c-main">
<div class="container-fluid">
<div class="fade-in">
<div class="card">
<div class="card-header">Tunnel Info</div>
<div class="card w-100">
<div class="card-body">
<table class="table table-responsive-sm table-hover table-outline mb-0">
<thead class="thead-light">
<tr>
<th>Tunnel Name</th>
<th class="text-center">Tunnel IP</th>
<th class="text-center">Tunnel ACL</th>
</tr>
{% for items in ipsec %}
<tbody>
<tr>
<td>{{ items.tunnel_name }}</td>
<td class="text-center">{{ items.tunnel_ip }}</td>
<td class="button"><a data-toggle="modal" data-target="#myModal" href="#">{{ items.tunnel_acl }}</a></td>
<div id="myModal" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Modal Header</h4>
</div>
<div class="modal-body">
<p>{{ results }}</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
{% endfor %}
</div>
</div>
</tr>
</tbody>
</thead>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
</main>
第一个函数“ def IPSEC_ANA(request)”正在表中呈现数据库中的所有内容,可以正常工作。
我的问题是试图在模态内部渲染上下文时出现第二个函数“ def IPSEC_ANA(request)”。
我无法正常工作。模态为空白。
我们将一如既往地为您提供帮助。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。