zoukankan      html  css  js  c++  java
  • 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',{})
  • 相关阅读:
    基础总结篇之一:Activity生命周期
    putExtra方法
    fork函数
    linux中fork()函数详解(原创!!实例讲解) (转载)
    系统调用wait、waitpid和exec函数
    版本控制工具VSS使用介绍
    学习进度条六(第七周)
    阶段冲刺4
    阶段冲刺3
    阶段冲刺2
  • 原文地址:https://www.cnblogs.com/ZHANG576433951/p/6885909.html
Copyright © 2011-2022 走看看