The rendering Process

The rendering process

  The rendering process takes the intermediate representation of template and context, and turns it into the final byte stream that can be served to the client.

  TemplateResponse allows you to register callbacksthat will be invoked when rendering has completed. Using this callback, you can defer critical processing until a pointwhere you can guarantee that rendered content will be available.

  def my_render_callback(response):

    pass

  def my_view(request):

    response = TemplateResponse()

    response.add_post_render_callback(my_render_callback)

    return response

   my_render_callback() will be invoked after the mytemplate.html has been rendered, and will be provided the fully rendered TemplateResponse instance as an argument.If the template has already been rendered, the callback will be invoked immediately.

   A TemplateResponse object can be used anywhere that a normal django.http.HttpResponse can be used.It can also be used as an alternative to calling render().

猜你喜欢

转载自www.cnblogs.com/BurgundyRed/p/9708866.html