Review three classic commands from last lesson
Django-admin Startproject Project Name # Build project Python manage.py startapp blog# build Project site Python manage.py runserver# start service # Runserver can be followed by a port number, indicating that the ports are running
Tmeplates:
650) this.width=650; "src=" Https://s4.51cto.com/wyfs02/M00/98/05/wKioL1k2V_OhVLyDAAF_joyk_2o137.png "title=" P1.png "alt=" Wkiol1k2v_ohvlydaaf_joyk_2o137.png "/>
(Pictures reproduced in the screen lesson)
In yesterday's Myblog\blog resume Templates folder
Structure Tree
MyBlog
|
|-----Blog
| |
| |-----templates
| | |
| | |-----index.html
650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M02/98/04/wKiom1k2WKSStuXFAAAuIadToqw993.png "title=" P2.png "alt=" Wkiom1k2wksstuxfaaauiadtoqw993.png "/>
The body of index is written in a line to prove that he is his own
Edit: views.py under the blog directory
Purpose: To indicate that Django reads the index.html file under the Templates directory
from django.shortcuts import render# default is Def index (request): Return render (Request, ' blog/index.html ') #反馈index. HTML content # Why not add templates content? #因为在settings. PY has this line of parameters TEMPLATES = [ { ' BACKEND ': ' Django.template.backends.django.DjangoTemplates ', ' DIRS ': [], ' 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 defaults to indicate that templates is hosting a folder for a Web page
650) this.width=650; "src=" Https://s4.51cto.com/wyfs02/M01/98/05/wKioL1k2WzfDSRxqAABtIkrlPoo136.png "title=" P3.png "alt=" Wkiol1k2wzfdsrxqaabtikrlpoo136.png "/>
Hey, it's not coming out.
650) this.width=650; "src=" Http://img.baidu.com/hi/jx2/j_0042.gif "alt=" J_0042.gif "/>650" this.width=650; "src=" Http://img.baidu.com/hi/jx2/j_0042.gif "alt=" J_0042.gif "/>650" this.width=650; "src=" http://img.baidu.com/hi/ Jx2/j_0042.gif "alt=" J_0042.gif "/>
Build DTL content:
What the hell is DTL?
The understanding is that if the Web page needs to pass small parameters, the dictionary is passed directly with DTL.
After using two small methods, you can complete
1.
Modify the views.py under the blog
DEF index: #return render (Request, ' blog/index.html ', {' Dictionary name passed ': ' corresponding content '}) return render (Request, ' Blog/index. html ', {' dtlname ': ' We are all very handsome '})
2.
Add a sentence to the body of index
<body>
We're done with the quick configuration of DTL.
650) this.width=650; "src=" Http://img.baidu.com/hi/jx2/j_0061.gif "alt=" J_0061.gif "/>650" this.width=650; "src=" Http://img.baidu.com/hi/jx2/j_0061.gif "alt=" J_0061.gif "/>650" this.width=650; "src=" http://img.baidu.com/hi/ Jx2/j_0061.gif "alt=" J_0061.gif "/>650" this.width=650; "src=" Http://img.baidu.com/hi/jx2/j_0061.gif "alt=" j_ 0061.gif "/>
• Dual-site templates
Directory structure
MyBlog
├─blog
││
│├─templates
││└─blog
││ └─index.html
├─blog2
│├─templates
││└─blog2
││ └─index.html
The body of index is written in a line to prove that he is his own
Edit: views.py under the blog directory
From django.shortcuts import render# has def index (request) By default: Return render (Request, ' blog/index.html ')
The body of index is written in a line to prove that he is his own
Edit: views.py under the blog directory
From django.shortcuts import render# has def index (request) By default: Return render (Request, ' blog2/index.html ')
----------------------------------------------------
650) this.width=650; "src=" Http://img.baidu.com/hi/jx2/j_0040.gif "alt=" J_0040.gif "/>650" this.width=650; "src=" Http://img.baidu.com/hi/jx2/j_0040.gif "alt=" J_0040.gif "/>650" this.width=650; "src=" http://img.baidu.com/hi/ Jx2/j_0040.gif "alt=" J_0040.gif "/>650" this.width=650; "src=" Http://img.baidu.com/hi/jx2/j_0040.gif "alt=" j_ 0040.gif "/>650) this.width=650;" src= "Http://img.baidu.com/hi/jx2/j_0040.gif" alt= "J_0040.gif"/>650 " this.width=650; "src=" Http://img.baidu.com/hi/jx2/j_0040.gif "alt=" J_0040.gif "/>"
Use
127.0.0.1:8000/blog/index.html
127.0.0.1:8000/blog2/index.html
Each can access the self-directory, note: If you do not create a separate folder under Templates is the default access to the blog directory index.html
Python 3.5 Django Notes (ii) Tmeplates and models