Python脚本之django

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Python脚本之django相关的知识,希望对你有一定的参考价值。

[[email protected] python]# tar -zxvf Django-1.5.1.tar.gz

[[email protected] python]# cd Django-1.5.1

[[email protected] Django-1.5.1]# python setup.py install

[[email protected] Django-1.5.1]# cd django/bin/

[[email protected] bin]# ./django-admin.py startproject myweb

[[email protected] bin]# cd myweb

[[email protected] myweb]# ./manage.py runserver 0.0.0.0:8000

#http://192.168.1.10:8000/

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

[[email protected] bin]# cd myweb

[[email protected] myweb]# pwd

/tmp/python/Django-1.5.1/django/bin/myweb/myweb

vi view.py

from django.http import HttpResponse

import datetime,time,os

def hello(request):

        return HttpResponse(‘hello my name is xk‘)

def current_time(request):

        now=datetime.datetime.now()

        html="It is now :%s"%now

        return HttpResponse(html)

def cpu(request):

        status=os.popen(‘top -bn 1‘).read()

        html="<pre>%s"%status

        return HttpResponse(html)

def hours_ahead(request,h):

        offset=int(h)

        dt=datetime.datetime.now() + datetime.timedelta(hours=offset)

        html="In %s hours later,It is %s"%(h,dt)

        return HttpResponse(html)

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

[[email protected] myweb]# vi urls.py

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


# Uncomment the next two lines to enable the admin:

# from django.contrib import admin

# admin.autodiscover()

from myweb.view import hello,current_time,cpu,hours_ahead


urlpatterns = patterns(‘‘,

    # Examples:

    # url(r‘^$‘, ‘myweb.views.home‘, name=‘home‘),

    # url(r‘^myweb/‘, include(‘myweb.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‘^hello/$‘,hello),

        (r‘^time/$‘,current_time),

        (r‘^cpu/$‘,cpu),

        (r‘^time/plus/(\d{1,2})/$‘,hours_ahead),

)


#http://192.168.1.10:8000/hello/

















本文出自 “银河系|计算机网络” 博客,请务必保留此出处http://qqran.blog.51cto.com/10014850/1963977

以上是关于Python脚本之django的主要内容,如果未能解决你的问题,请参考以下文章

Python脚本之django

python脚本之paramiko

Python脚本之socket

Python脚本之django---mysql

Python脚本之Multiprocessing 多线程

python脚本之与mysql交互