Chinaunix首页 | 论坛 | 博客
  • 博客访问: 276407
  • 博文数量: 103
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 705
  • 用 户 组: 普通用户
  • 注册时间: 2013-05-02 16:15
文章分类

全部博文(103)

文章存档

2014年(8)

2013年(95)

我的朋友

分类: Python/Ruby

2013-09-11 17:08:42

表单的应用

from django.shortcuts import render_to_response

from django.http import HttpResponse

from django import forms           导入表单模块

 

from  sshCMD.models import SerInfo

 

import paramiko

import os,sys

 

class UserForm(forms.Form):

    name=forms.CharField()                             定义表单类

 

def register(req):

    if req.method == "POST":

        form = UserForm(req.POST)                     将类与表单绑定

        if form.is_valid():

            print form.cleaned_data

            return HttpResponse('ok')

    else:

        form = UserForm()

    return render_to_response('register.html',{'form':form,})

 

def index(request):

    return render_to_response('index.html',)

 

def list_ip(request):

    a = "hello"

    ip_object = SerInfo.objects.all()

    return render_to_response('index.html',{"ips":ip_object,})

 

------------------------------------------------------------------------------------

vim Templates/register.html

 

   

        {{ form }}

       

   

------------------------------------------------------------

from django.conf.urls import patterns, include, url

#add by hans 20130906

from sshCMD.views import index,list_ip,register

 

from django.conf import settings

 

# Uncomment the next two lines to enable the admin:

from django.contrib import admin

admin.autodiscover()

 

urlpatterns = patterns('',

    # Examples:

    # url(r'^$', 'serManager.views.home', name='home'),

    # url(r'^serManager/', include('serManager.foo.urls')),

 

    # Uncomment the admin/doc line below to enable admin documentation:

    # url(r'^admin/doc/', include('django.contrib.admindocs.urls')),

 

    # Uncomment the next line to enable the admin:

    url(r'^admin/', include(admin.site.urls)),

    (r'^$',index),

    (r'bootstrap/(?P.*)$','django.views.static.serve',{'document_root':settings.MEDIA_ROOT,}),

#    (r'^search/$',search_form),

    (r'^ips/$',list_ip),

    (r'^reg/$',register),

 

)

 

MIDDLEWARE_CLASSES = (

    'django.middleware.common.CommonMiddleware',

    'django.contrib.sessions.middleware.SessionMiddleware',

#    'django.middleware.csrf.CsrfViewMiddleware',

    'django.contrib.auth.middleware.AuthenticationMiddleware',

    'django.contrib.messages.middleware.MessageMiddleware',

    # Uncomment the next line for simple clickjacking protection:

    # 'django.middleware.clickjacking.XFrameOptionsMiddleware',

)

阅读(932) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~