首页 > 代码库 > django中html文件的配置
django中html文件的配置
先建立一个app,别忘了在seetings中加入你新建的qpp项目
链接:http://www.cnblogs.com/ZHANG576433951/p/6853362.html
在blog的目录下建立一个文件夹templates,在templates中写入index文件,如图:
需修改文件有 urls.py和views.py
url.py
1 """app URL Configuration 2 3 The `urlpatterns` list routes URLs to views. For more information please see: 4 https://docs.djangoproject.com/en/1.9/topics/http/urls/ 5 Examples: 6 Function views 7 1. Add an import: from my_app import views 8 2. Add a URL to urlpatterns: url(r‘^$‘, views.home, name=‘home‘) 9 Class-based views 10 1. Add an import: from other_app.views import Home 11 2. Add a URL to urlpatterns: url(r‘^$‘, Home.as_view(), name=‘home‘) 12 Including another URLconf 13 1. Import the include() function: from django.conf.urls import url, include 14 2. Add a URL to urlpatterns: url(r‘^blog/‘, include(‘blog.urls‘)) 15 """ 16 from django.conf.urls import url 17 from django.contrib import admin 18 from blog.views import index 19 urlpatterns = [ 20 url(r‘^admin/‘, admin.site.urls), 21 url(r‘^blog/index/\d{2}/$‘, index), 22 ]
views.py其中有两种写法
1 from django.http import HttpResponse 2 from django.shortcuts import render 3 from django.shortcuts import render_to_response 4 from django.template import loader,Context 5 6 # Create your views here. 7 ‘‘‘def index(request): 8 t= loader.get_template(‘index.html‘) 9 C = Context({}) 10 return HttpResponse(t.render(C)) 11 #return render(request,‘index.html‘)‘‘‘ 12 def index(request): 13 return render_to_response(‘index.html‘,{})
django中html文件的配置
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。