How to use the Render template method to display content.
1. Create a project Dream
django-admin.py Startproject Dream
CD dream and create an app
Python manage.py Startapp Learn
2, add the created application-learn to settings. In Installed_apps
INSTALLED_APPS
=
(
‘django.contrib.admin‘
,
‘django.contrib.auth‘
,
‘django.contrib.contenttypes‘
,
‘django.contrib.sessions‘
,
‘django.contrib.messages‘
,
‘django.contrib.staticfiles‘
,
‘learn‘
,
)
3. Open learn/views.py Write a view of the home page from django.shortcuts import render def home (Request): Return render (Request, ' home.htm L ') 4, Focus: Create a templates directory under the Learn directory and create a home.html file under it default configuration, Django template will automatically find files in the Templates folder under the app
dream
├── learn
│ ├── __init__.py
│ ├── admin.py
│ ├── migrations
│ │ └── __init__.py
│ ├── models.py
│ ├── templates
│ │ └── home.html
│ ├── tests.py
│ └── views.py
├── manage.py
└── dream
├── __init__.py
├── settings.py
├── urls.py
└── wsgi.py
4 directories, 12 files
5, now is to write the corresponding content in the home.html <! Doctype>
Django Learning-2 templates