django中html檔案的配置

來源:互聯網
上載者:User

標籤: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檔案的配置

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.