📜  http 响应模板 - Python 代码示例

📅  最后修改于: 2022-03-11 14:45:43.921000             🧑  作者: Mango

代码示例1
from django.http import HttpResponse
from django.template import loader

from .models import Question


def index(request):
    latest_question_list = Question.objects.order_by('-pub_date')[:5]
    template = loader.get_template('polls/index.html')
    context = {
       'latest_question_list': latest_question_list,
    }
    return HttpResponse(template.render(context, request))