Simple python django framework development example, pythondjango

Source: Internet
Author: User

Simple python django framework development example, pythondjango

Create the views. py file in the/home/ubuntu/mysite directory as follows:

  

from django.http import HttpResponse,Http404import datetimeimport osdef sayhi(request):    return HttpResponse('Hello World,this is my first Web page')

  

def current_time(request):    ow = datetime.datetime.now()    html = '

  

def cpu(request):    cpu_status = os.popen('cat /proc/cpuinfo').read()    html = '

  

def hours_ahead(request,offset):    try:        offset = int(offset)    except ValueError:        raise Http404()    dt = datetime.datetime.now() + datetime.timedelta(hours=offset)    html = '

  

Modify the urls. py file under/home/ubuntu/mysite:

Add code:

From mysite. views import sayhi
From mysite. views import current_time
From mysite. views import cpu
From mysite. views import hours_ahead

Url (R' ^ views/$ ', sayhi ),
Url (R' ^ time/$ ', current_time ),
Url (R' ^ cpu/$ ', cpu ),
Url (R' ^ time/plus/(\ d +)/$ ', hours_ahead)

 

Run pythom manage. py runserver 0.0.0.0: 9999

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.