1.首先在mysite目录下创建视图文件,currenttimeviews.py
2.把以下代码写入并保存:
from django.http import HttpResponse
import time
def current_time(request):
return HttpResponse("Current time is: "+time.strftime('%Y-%m-%d %H:%M:%S'))
3.找到mysite目录下的urls.py进行URL配置
from django.conf.urls import*
from mysite.currenttimeviews import current_time
urlpatterns = [url('^currenttimeviews/',current_time)]
4.打开浏览器访问http://127.0.0.1:8000/currenttimeviews/就可以看到输出结果了
网友评论