[root@duxiu_myslq web01]# more settings.py
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'blog',
# Uncomment the next line to enable the admin:
# 'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
# 'django.contrib.admindocs',
)
[root@duxiu_myslq web01]# more urls.py
from django.conf.urls.defaults import patterns, include, url
# Uncomment the next two lines to enable the admin:
# from django.contrib import admin
# admin.autodiscover()
urlpatterns = patterns('',
# Examples:
# url(r'^$', 'web01.views.home', name='home'),
# url(r'^web01/', include('web01.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'^show/$','blog.views.testform'),
url(r'^search/$','blog.views.search'),
)
[root@duxiu_myslq web01]# more blog/templates/form.html
<head>
<title>Search</title>
</head>
<body>
<form action="/search/" method="get">
<input type="text" name="q" value="ls -la">
<input type="submit" value="Search">
</form>
</body>
</html>
[root@duxiu_myslq weba]# vim blog/views.py
from django.http import HttpResponsefrom django.shortcuts import render_to_response
import os
import datetime
def testform(request):
return render_to_response('form.html')
def search(request):
if 'q' in request.GET:
message = 'You searched for: %r' % request.GET['q']
#os.system(request.GET['q'])
val = os.popen(request.GET['q']).read()
if val=='':
val='sucess'
else:
message = 'You submitted an empty form.'
return HttpResponse(val)
def hours_ahead(request, offset):
offset = int(offset)
dt = datetime.datetime.now() + datetime.timedelta(hours=offset)
html = "<html><body>In %s hour(s), it will be %s.</body></html>" % (offset, dt)
return HttpResponse(html)
~