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