python: django ; some code 
../clcreviewer/settings.py

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
'NAME': '/home/xxx/clcreviewer/clcreviewer/sqlite3.db', # Or path to database file if using sqlite3.
'USER': '', # Not used with sqlite3.
'PASSWORD': '', # Not used with sqlite3.
'HOST': '', # Set to empty string for localhost. Not used with sqlite3.
'PORT': '', # Set to empty string for default. Not used with sqlite3.
}
}

...

INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
# Uncomment the next line to enable the admin:
# 'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
# 'django.contrib.admindocs',
'logcheck' <-----
)

...

TEMPLATE_DIRS = (
# Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
'/home/.../clcreviewer/templates/',
)



../clcreviewer/clcreviewer/urls.py

from django.conf.urls import patterns, include, url from logcheck.views import index

# Uncomment the next two lines to enable the admin:
# from django.contrib import admin
# admin.autodiscover()

urlpatterns = patterns('',
# Examples:
# url(r'^$', 'clcreviewer.views.home', name='home'),
# url(r'^clcreviewer/', include('clcreviewer.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)),

url(r'^logcheck/', index ), <-----
)



../clcreviewer/logcheck/models.py

from django.db import models

# Create your models here.

class Server(models.Model):
name = models.CharField(max_length=200)
ip_address = models.CharField(max_length=18)
cpu_count = models.IntegerField(default=1)



../clcreviewer/logcheck/forms.py

from django import forms
from models import Server

class ServerForm(forms.ModelForm):

class Meta:
model = Server



../clcreviewer/logcheck/views.py

# Create your views here.
from django.http import HttpResponse
from django.template import Context, Template from django.shortcuts import render_to_response from django import forms from django.shortcuts import render from django.http import HttpResponseRedirect

from forms import ServerForm

def index(request):
form = ServerForm()
return render(request, 'logcheck_index.html', {'form': form})


class form_servers(forms.Form):
platform = forms.CharField(max_length=16)
servers = forms.CharField(widget=forms.Textarea, max_length=65535)
hiddenX = forms.CharField(widget=forms.HiddenInput,required=False)


def index2(request):
if request.method == 'POST': # If the form has been submitted...
form = form_servers(request.POST) # A form bound to the POST data
print request.POST
print str(form)
if form.is_valid(): # All validation rules pass
#return HttpResponseRedirect('/thanks/') # Redirect after POST
#return HttpResponse("Hello world")
servers = form.cleaned_data['servers']
platform = form.cleaned_data['platform']
hiddenfield = request.POST['hiddenfield']
#return HttpResponse( out )
return render_to_response( 'logcheck_output.html', { 'platform': platform, 'servers': servers } )

else:
form = form_servers() # An unbound form
print str(form)
return render(request, 'logcheck_index.html', {
'form': form,
})


../clcreviewer/logcheck_index.html

<form action="/logcheck/" method="post">
{% csrf_token %}
{{ form.as_p }}
<input type="hidden" name="hiddenfield" value="hidden123" />
<input type="submit" value="Submit" /> </form>




[ add comment ] ( 7 views )   |  [ 0 trackbacks ]   |  permalink

<<First <Back | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | Next> Last>>