views.py
from django.shortcuts import render,HttpResponse # Create your views here. def index(request): age = 1 return render(request,'index.html',{'age':age})
index.html
Title 我是首页
{ { age }} {#在页面中判断 #} {% if age > 18 %}已经成年了
{% elif age < 18 %}还没有成年
{% else %}正好成年
{% endif %}
urls.py
from django.conf.urls import url from django.contrib import admin from app01 import views urlpatterns = [ url(r'^admin/', admin.site.urls), url(r'index/', views.index) ]