from django.shortcuts import render
from django.http import HttpResponse
from django.shortcuts import redirect
from django.template.loader import get_template
from datetime import datetime
from .models import Post
# Create your views here.
def homepage(request):
template = get_template('index.html')
html = template.render(locals())
return HttpResponse(html)
def index(request):
template = get_template('index.html')
posts = Post.objects.all()
now = datetime.now()
html = template.render(locals())
return HttpResponse(html)
def home(request):
template = get_template('home.html')
posts = Post.objects.all()
now = datetime.now()
html = template.render(locals())
return HttpResponse(html)
def showpost(request,slug):
template = get_template('post.html')
try:
post = Post.objects.get(slug = slug)
if post != None:
html = template.render(locals())
return HttpResponse(html)
except:
return redirect('/')
def showdetail(request,slug):
template = get_template('show.html')
try:
post = Post.objects.get(slug = slug)
if post != None:
html = template.render(locals())
return HttpResponse(html)
except:
return redirect('/')
Django-Web小技巧 get_template 使用
最新推荐文章于 2025-07-02 00:50:19 发布