码迷,mamicode.com
首页 > 其他好文 > 详细

Django学习笔记1

时间:2018-05-04 17:12:26      阅读:158      评论:0      收藏:0      [点我收藏+]

标签:请求   app   template   name   os.path   short   AC   tco   debug   

重点在注释#

1.views.py

 1 from django.shortcuts import render
 2 from django.http import *
 3 #from django.template import RequestContext,loader
 4 
 5 # Create your views here.
 6 
 7 def index(request):#request是已经封装好的,包括请求头
 8     # temp=loader.get_template(booktest/test.html)#loader表示加载,得到某模板
 9     # return HttpResponse(temp.render())#将模板渲染
10     return  render(request,booktest/test.html,)#是上面两行代码的封装,简单些,
11     #‘booktest/test.html‘是templates下的路径,但我们还需要templates的路径,需要到setting.py下配置

2.setting.py

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))#我猜是获得book_hero的路径

 

TEMPLATES = [
    {
        BACKEND: django.template.backends.django.DjangoTemplates,
        DIRS: [os.path.join(BASE_DIR,templates)],#路径拼接,BASE_DIR在第16行,后面加上templates,
        # C:\Users\OOK\Desktop\book_hero\templates 如果templates放在app里,则这里不用配置
        APP_DIRS: True,
        OPTIONS: {
            context_processors: [
                django.template.context_processors.debug,
                django.template.context_processors.request,
                django.contrib.auth.context_processors.auth,
                django.contrib.messages.context_processors.messages,
            ],
        },
    },
]

 

Django学习笔记1

标签:请求   app   template   name   os.path   short   AC   tco   debug   

原文地址:https://www.cnblogs.com/O-OK/p/8990832.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!