Django 學習筆記(三)模板導入
阿新 • • 發佈:2017-08-07
文件 文件中 訪問 from lang sts class rom 網頁
本章內容是將一個html網頁放進模板中,並運行服務器將其展現出來。
平臺:windows平臺下Liunx子系統
目前的目錄:
hello ├── manage.py ├── hello │ ├── __init__.py │ ├── settings.py │ ├── urls.py │ └── wsgi.py └── HelloWorld ├── __init__.py ├── admin.py ├── apps.py
├── models.py ├── tests.py
└── views.py
我們只需要在HelloWorld中增加一個文件夾templates,把html網頁放進這個文件夾內
<!DOCTYPE html> <html lang="zh-cn"> <head> <title>welcome</title> <meta charset="utf-8"> </head> <body> <h1> Hello World!</h1> </body> </html>
現在的,目錄應該是:
hello ├── manage.py ├── hello │ ├── __init__.py │ ├── settings.py │ ├── urls.py │ └── wsgi.py └── HelloWorld ├── templates │ └──index.html ├── __init__.py ├── admin.py ├── apps.py ├── models.py ├── tests.py └── views.py
然後在views.py文件中,輸入下面內容即可
from django.shortcuts import render def index(request): return render(request,‘index.html‘)
最後運行服務器,即可訪問模板文件
Django 學習筆記(三)模板導入