django 부분 코드

ngingx 프로필 업데이트 코드 및 전시
파이썬 코드
# -*- coding: utf-8 -*-
from django.shortcuts import render
from django.http import HttpResponseRedirect
from django.shortcuts import render_to_response
from django.contrib import auth
from django.contrib.auth.decorators import login_required
import difflib
import os, sys
import requests 
import re
import urllib, urllib2
from django.core.paginator import Paginator
import commands
import MySQLdb
import time, datetime
from django.views.decorators.csrf import csrf_exempt
from django.http import HttpResponse
from django.template import RequestContext
from webip.models import AccessDizhi
from nginxet.models import NginxET, NginxEThistory
from django.shortcuts import get_object_or_404
from nginxet.form import HostsListForm
@csrf_exempt
def nginxfile(request):
    if request.method == 'POST':
        date1 = datetime.datetime.now()
        date2 = date1 + datetime.timedelta(hours=14)
        date = date2.strftime('%Y-%m-%d %H:%M:%S')
        all_server1 = NginxET.objects.all().values_list('dirname','filename')
        c = []
        for i in all_server1:
            c.append(i)
        for root,dirs,files in os.walk('/data/nginxet/'):
            dir_name = root.split('/')[3]
            if dir_name:
               for filed in files:
                   if filed:
                      filed3 = (u'%s' %dir_name, u'%s' %filed)
                      abc = c.count(filed3)
                      if abc > 0:
                          pass
                      else:
                          filedd = root+'/'+filed
                          filed1 = open(filedd, 'r')
                          messages = filed1.read()
                          NginxET.objects.create(dirname=dir_name,filename=filed,message=messages,onlinetime=date,updatemessage=1,updatetime=date)
                          filed1.close()
                   else:
                      pass  
        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))
    else:
        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))
models  
# -*- coding: utf-8 -*-
from django.db import models
class NginxET(models.Model):
    dirname = models.CharField(max_length=50, verbose_name=u'    ')
    filename = models.CharField(max_length=100, verbose_name=u'   ')
    message = models.TextField(verbose_name=u'nginx  ')
    updatemessage = models.TextField(verbose_name=u'    ')
    onlinetime = models.DateTimeField(max_length=100, blank=True, verbose_name=u'    ')
    updatetime = models.DateTimeField(max_length=100, blank=True, verbose_name=u'    ')
    def __unicode__(self):
        return u'%s - %s - %s - %s' %(self.dirname, self.filename, self.message, self.updatemessage, self.updatetime)
    class Meta:
        verbose_name = u'    '
        verbose_name = u'   '
form  
# -*- coding: utf-8 -*-
from django import forms
from nginxet.models import NginxET
class HostsListForm(forms.ModelForm):
#class HostsListForm(forms.Form):
    class Meta:
        model = NginxET
        fields = "__all__"
        widgets = {
          'dirname': forms.TextInput(attrs={'class': 'form-control'}),
          'filename': forms.TextInput(attrs={'class': 'form-control'}),
#          'message': forms.CharField(widget=forms.Textarea),
          'message': forms.TextInput(),
          'updatemessage': forms.TextInput(attrs={'class': 'form-control'}),
          'onlinetime': forms.TextInput(attrs={'class': 'form-control'}),
          'updatetime': forms.TextInput(attrs={'class': 'form-control'}),
        }

html 코드
{% extends "index.html" %}
{% block title %}OMS{% endblock %}
{% block css %}


{% endblock %}
{% block content %}
      
      
            
                 
                      
                           {% if all_host_list %}
                           
                               
                                   
                                      
                                      
                                      
                                      
                                      
                                   
                               
                               
                               {% for all_host in all_host_list %}
                                   
                                      
                                      
                                      
                                      
                                      
                                      
                                   
                               {% endfor %}
                               
IDIP 주소 파일 이름 상위 시간 업데이트 시간 {{forloop.counter} {{all host.dirname} {all host.filename} {{all host.onlinetime}} {{all host.updatetime}내용 전시
                                           역사.
                                           최근 변경 내용 비교
                                           떠밀다
                           {% endif %}
                            
                                 
                                       
                                 
                                 
                                      
                                            수색하다
                                            히스토리 검색
                                           {% if all_host_list.has_previous %}
                                                 이전 페이지
                                           {% endif %}
                                           
{{all host list.number} 페이지/{all host list.paginator.num pages} 페이지
                                           
                                           {% if all_host_list.has_next %}
                                                 다음 페이지
                                           {% endif %}
                                      
                                 
                            
                         
                     
                 
                 
모두 업데이트
                
{% endblock %}

좋은 웹페이지 즐겨찾기