標籤:ase other get 修改檔案 context import lan ext span
先建立一個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 views10 1. Add an import: from other_app.views import Home11 2. Add a URL to urlpatterns: url(r‘^$‘, Home.as_view(), name=‘home‘)12 Including another URLconf13 1. Import the include() function: from django.conf.urls import url, include14 2. Add a URL to urlpatterns: url(r‘^blog/‘, include(‘blog.urls‘))15 """16 from django.conf.urls import url17 from django.contrib import admin18 from blog.views import index19 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檔案的配置