This module provides generic content rendering to make response using requested Accept mimetypes. In HTTP terminology, it’s called as content negotiation.
Plastic provides two types of rendering methods:
Renders the suitable response using content negotiation. It’s aware of given request‘s Accept header.
If there’s no matched mimetype to request‘s Accept list, it raises NotAcceptable error.
If chosen mimetype is associated to serializer (see BaseApp.add_serializer()) it passes value to the serializer and rest of arguments are just ignored.
If chosen mimetype is associated to suffix (see BaseApp.associate_mimetypes() method) it appends the suffix to the given template path and then calls render_template() function with the same arguments except value.
Parameters: |
|
---|---|
Returns: | a rendered response |
Return type: | |
Raises: |
|
Helper function that renders a template of the given path with values (and keywords). It’s a shortcut of BaseApp.render_template() method.
@App.route('/<int:user_id>')
def user_profile(request, user_id):
global users
user = users[user_id]
return render_template(request, 'user_profile.html',
user_id=user_id, user=user)
You have to pass the path without specific suffix. The last suffix will be used for determining what template engine to use. For example, if there is user_profile.html.mako file in the template_path and 'mako' is associated to Mako template engine in template_engines mapping, the following code will find user_profile.html.mako (not user_profile.html) and render it using Mako:
render_template(request, 'user_profile.html')
In other words, you have to append a suffix to determine what template engine to use into filenames of templates.
Parameters: |
|
---|---|
Returns: | a rendered result |
Return type: | basestring |
Raises plastic.exceptions.RenderError: | |
when there are no matched template files |
See also