我的第一个Django页面,动态显示时间的
文件结构
1.views.py
'''
Created on 2015-6-8
@author: Zcy
'''
from django.http import HttpResponse
import datetime
def current_datetime(request):
now=datetime.datetime.now()
html="<html><body>It is now %s.</body></html>" %now
return HttpResponse(html)
2.urls.py
from django.conf.urls import patterns, include, url
from mysite.views import current_datetime
# Uncomment the next two lines to enable the admin:
# from django.contrib import admin
# admin.autodiscover()
urlpatterns = patterns('',
(r'^time/$', current_datetime),
)
manage.py右击python run
然后访问http://127.0.0.1:8000/time/