其他分享
首页 > 其他分享> > 【django学习-09】模板1:万能的句点号

【django学习-09】模板1:万能的句点号

作者:互联网

urls.py
from django.contrib import admin
from django.urls import path
from blog import views

urlpatterns = [
    path('admin/', admin.site.urls),
    path('index/', views.index),
]

views.py
from django.shortcuts import render,HttpResponse

# Create your views here.
import datetime
def index(req):
    str = "zfc的健康减肥接口"
    L = [1,22,333]
    dic = {
        "name":"xwl",
        "age":18
    }
    cur_time = datetime.datetime.now()

    class Person:
        def __init__(self,name,age):
            self.name = name
            self.age = age

    person = Person("gmm",22)

    return render(req,"index.html",locals())

index.html
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<h1>{{ str }}</h1>
<h1>{{ L.0 }}</h1>
<h1>{{ dic.name }}</h1>
<h1>{{ person.name }}</h1>
<h1>{{ cur_time.year }}</h1>

</body>
</html>

标签:index,name,09,视图,django,句点,import,上下文,模板
来源: https://www.cnblogs.com/xwltest/p/16667240.html