python文件
csrf_exempt
def nginxhistory(request):
if request.method == "POST":
ret = request.POST.get('code')
id2 = request.GET['abc']
ret = str(ret)
ret1 = ret.replace('\r','')
ret2 = NginxET.objects.values_list('message', flat=True).get(id=id2)
ret2 = str(ret2)
dir1 = NginxET.objects.values_list('dirname', flat=True).get(id=id2)
file1 = NginxET.objects.values_list('filename', flat=True).get(id=id2)
text1_lines = ret1.splitlines()
text2_lines = ret2.splitlines()
d = difflib.HtmlDiff()
diff = d.make_file(text1_lines,text2_lines)
if text1_lines == text2_lines:
return HttpResponse('配置文件没有更新不需要写入数据库^-^!!!!!!')
else:
date1 = datetime.datetime.now()
date2 = date1 + datetime.timedelta(hours=14)
date = date2.strftime('%Y-%m-%d %H:%M:%S')
NginxEThistory.objects.create(dirname=dir1,filename=file1,message=ret2,onlinetime=date)
NginxET.objects.filter(id=id2).update(message=ret1,updatetime=date)
all_server = NginxET.objects.all()
paginator = Paginator(all_server,20)
try:
page = int(request.GET.get('page','1'))
except ValueError:
page = 1
try:
all_server = paginator.page(page)
except :
all_server = paginator.page(paginator.num_pages)
return render_to_response('nginxet.html',
{'all_host_list': all_server, 'page': page, 'paginator':paginator},context_instance=RequestContext(request))
html文件
{% extends "index.html" %}
{% block title %}OMS{% endblock %}
{% block css %}
<!-- DataTables-->
<link rel="stylesheet" href="/static/plugins/dataTables/css/dataTables.css">
{% endblock %}
{% block content %}
<form action="http://:8999/nginxet/" method="POST">
<div class="row">
<div class="col-md-12">
<div class="panel panel-default">
<div class="panel-body">
{% if all_host_list %}
<table id="example" class="table table-striped table-bordered" cellspacing="0" width="100%">
<thead>
<tr>
<th>ID</th>
<th>IP地址</th>
<th>文件名</th>
<th>上线时间</th>
<th>更新时间</th>
</tr>
</thead>
<tbody>
{% for all_host in all_host_list %}
<tr>
<td>{{ forloop.counter }}</td>
<td>{{ all_host.dirname }}</td>
<td>{{ all_host.filename }}</td>
<td>{{ all_host.onlinetime }}</td>
<td>{{ all_host.updatetime }}</td>
<td><a href="{% url 'message' id=all_host.id %}" class="btn btn-info btn-sm">内容展示</a>
<a href="http://:8999/nginx_update/?update=1" style="color:white" class="btn btn-danger btn-sm" role="button">历史</a>
<a href="http://:8999/nginx_diff/?id={{ all_host.id }}" class="btn btn-info btn-sm">最近一次更改比较</a>
<a href="http://:8999/nginx/?id={{ all_host.id }}" class="btn btn-info btn-sm">推送</a></td>
</tr>
{% endfor %}
</tbody>
</table>
{% endif %}
<div class="row">
<div class="col-xs-6">
<div class="dataTables_info" id="example_info" role="alert" aria-live="polite" aria-relevant="all"></div>
</div>
<div class="col-xs-6">
<div class="dataTables_paginate paging_simple_numbers" id="exmaple_paginate">
<a href="{% url 'sousuo' %}" class="btn btn-info btn-sm" role="button">搜索</a>
<a href="{% url 'sousuoh' %}" class="btn btn-info btn-sm" role="button">历史搜索</a>
{% if all_host_list.has_previous %}
<a href="?page={{ all_host_list.previous_page_number }}">上一页</a>
{% endif %}
<span class="current">
第{{ all_host_list.number }}页,共{{ all_host_list.paginator.num_pages }}页
</span>
{% if all_host_list.has_next %}
<a href="?page={{ all_host_list.next_page_number }}">下一页</a>
{% endif %}
</div>
</div>
</div> <!--row end-->
</div>
</div>
</div>
<div style = "text-align: center">
<button type="submit" class="btn btn-primary">全部更新</button>
</div>
</form>
{% endblock %}
转载于:https://blog.51cto.com/10265013/1910977