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 %}


{% endblock %}
{% block content %}
       
      
            
                 
                      
                           {% if all_host_list %}
                           
                               
                                   
                                      ID
                                      IP地址
                                      文件名
                                      上线时间
                                      更新时间
                                   
                               

                               
                               {% for all_host in all_host_list %}
                                   
                                      {{ forloop.counter }}
                                      {{ all_host.dirname }}
                                      {{ all_host.filename }}
                                      {{ all_host.onlinetime }}
                                      {{ all_host.updatetime }}
                                      内容展示
                                          历史
                                          最近一次更改比较
                                          推送
                                   
                               {% endfor %}
                               
                            
                           {% endif %}