- class django.views.generic.base.ContextMixin¶
- New in Django 1.5.
Returns a dictionary representing the template context. The keyword arguments provided will make up the returned context. Example usage:
def get_context_data(self, **kwargs): context = super(RandomNumberView, self).get_context_data(**kwargs) context['number'] = random.randrange(1, 100) return context
The template context of all class-based generic views include a view variable that points to the View instance.
Use alters_data where appropriate
Note that having the view instance in the template context may expose potentially hazardous methods to template authors. To prevent methods like this from being called in the template, set alters_data=True on those methods. For more information, read the documentation on rendering a template context.
- class django.views.generic.base.TemplateResponseMixin¶
Provides a mechanism to construct a TemplateResponse, given suitable context. The template to use is configurable and can be further customized by subclasses.
The full name of a template to use as defined by a string. Not defining a template_name will raise a django.core.exceptions.ImproperlyConfigured exception.
The response class to be returned by render_to_response method. Default is TemplateResponse. The template and context of TemplateResponse instances can be altered later (e.g. in template response middleware).
If you need custom template loading or custom context object instantiation, create a TemplateResponse subclass and assign it to response_class.
- New in Django 1.5: The content_type attribute was added.
The content type to use for the response. content_type is passed as a keyword argument to response_class. Default is None – meaning that Django uses DEFAULT_CONTENT_TYPE.
- render_to_response(context, **response_kwargs)¶
Returns a self.response_class instance.
If any keyword arguments are provided, they will be passed to the constructor of the response class.
Calls get_template_names() to obtain the list of template names that will be searched looking for an existent template.
Having trouble? We'd like to help!
- Try the FAQ — it's got answers to many common questions.
- Search for information in the archives of the django-users mailing list, or post a question.
- Ask a question in the #django IRC channel, or search the IRC logs to see if it has been asked before.
- If you notice errors with this documentation, please open a ticket and let us know! Please only use the ticket tracker for criticisms and improvements on the docs. For tech support, use the resources above.