欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Python27 demo 访问html

程序员文章站 2022-04-01 22:06:17
...
工程名untitle
应用名dd
访问:http://localhost:8000/f/
显示f.html文件内容

urls.py--配置请求
from django.conf.urls import patterns, include, url
from django.contrib import admin
from dd.views import current_datetime
from dd.views import get_html
from django.shortcuts import render_to_response


urlpatterns = patterns('',
    # Examples:
    # url(r'^$', 'untitled.views.home', name='home'),
    # url(r'^blog/', include('blog.urls')),

    url(r'^admin/', include(admin.site.urls)),
    url(r'^time/', current_datetime),
    url(r'^f/', 'dd.views.get_html'),# 该方式和下面的方式都可以调用get_html方法
    url(r'^f1/', get_html),#
)



views.py
from django.http import HttpResponse
from django import template
from django.template import Context, Template
from django.shortcuts import render_to_response,render
import datetime

def get_html(request):
    #return render(request,'sub//f1.html')
    return render(request,'f.html') #展示f.html文件

def current_datetime(request):
    now=datetime.datetime.now()
    html="<html><body>%s</body></html>" %now
    return HttpResponse(html)


templates目录下面f.html