Single object mixinsLink para este cabeçalho
SingleObjectMixinLink para este cabeçalho
- class django.views.generic.detail.SingleObjectMixinLink para esta definição
Provides a mechanism for looking up an object associated with the current HTTP request.
Métodos e Atributos
- modelLink para esta definição
The model that this view will display data for. Specifying
model = Foois effectively the same as specifyingqueryset = Foo.objects.all(), whereobjectsstands forFoo’s default manager.
- querysetLink para esta definição
Um “QuerySet” quere representa os objetos. Caso previamente informado um valor, o valor da “queryset” substitui o valor o primeiro por
model.
- slug_fieldLink para esta definição
The name of the field on the model that contains the slug. By default,
slug_fieldis'slug'.
- slug_url_kwargLink para esta definição
The name of the URLConf keyword argument that contains the slug. By default,
slug_url_kwargis'slug'.
- pk_url_kwargLink para esta definição
The name of the URLConf keyword argument that contains the primary key. By default,
pk_url_kwargis'pk'.
- context_object_nameLink para esta definição
Designates the name of the variable to use in the context.
- query_pk_and_slugLink para esta definição
-
If
True, causesget_object()to perform its lookup using both the primary key and the slug. Defaults toFalse.This attribute can help mitigate insecure direct object reference attacks. When applications allow access to individual objects by a sequential primary key, an attacker could brute-force guess all URLs; thereby obtaining a list of all objects in the application. If users with access to individual objects should be prevented from obtaining this list, setting
query_pk_and_slugtoTruewill help prevent the guessing of URLs as each URL will require two correct, non-sequential arguments. Simply using a unique slug may serve the same purpose, but this scheme allows you to have non-unique slugs.
- get_object(queryset=None)Link para esta definição
Returns the single object that this view will display. If
querysetis provided, that queryset will be used as the source of objects; otherwise,get_queryset()will be used.get_object()looks for apk_url_kwargargument in the arguments to the view; if this argument is found, this method performs a primary-key based lookup using that value. If this argument is not found, it looks for aslug_url_kwargargument, and performs a slug lookup using theslug_field.
- get_queryset()Link para esta definição
Returns the queryset that will be used to retrieve the object that this view will display. By default,
get_queryset()returns the value of thequerysetattribute if it is set, otherwise it constructs aQuerySetby calling theall()method on themodelattribute’s default manager.
- get_context_object_name(obj)Link para esta definição
Return the context variable name that will be used to contain the data that this view is manipulating. If
context_object_nameis not set, the context name will be constructed from themodel_nameof the model that the queryset is composed from. For example, the modelArticlewould have context object named'article'.
- get_context_data(**kwargs)Link para esta definição
Returns context data for displaying the list of objects.
The base implementation of this method requires that the
self.objectattribute be set by the view (even ifNone). Be sure to do this if you are using this mixin without one of the built-in views that does so.It returns a dictionary with these contents:
object: The object that this view is displaying (self.object).context_object_name:self.objectwill also be stored under the name returned byget_context_object_name(), which defaults to the lowercased version of the model name.
- get_slug_field()Link para esta definição
Returns the name of a slug field to be used to look up by slug. By default this simply returns the value of
slug_field.
SingleObjectTemplateResponseMixinLink para este cabeçalho
- class django.views.generic.detail.SingleObjectTemplateResponseMixinLink para esta definição
A mixin class that performs template-based response rendering for views that operate upon a single object instance. Requires that the view it is mixed with provides
self.object, the object instance that the view is operating on.self.objectwill usually be, but is not required to be, an instance of a Django model. It may beNoneif the view is in the process of constructing a new instance.Extends
Métodos e Atributos
- template_name_fieldLink para esta definição
The field on the current object instance that can be used to determine the name of a candidate template. If either
template_name_fielditself or the value of thetemplate_name_fieldon the current object instance isNone, the object will not be used for a candidate template name.
- template_name_suffixLink para esta definição
The suffix to append to the auto-generated candidate template name. Default suffix is
_detail.
- get_template_names()Link para esta definição
Returns a list of candidate template names. Returns the following list:
the value of
template_nameon the view (if provided)the contents of the
template_name_fieldfield on the object instance that the view is operating upon (if available)<app_label>/<model_name><template_name_suffix>.html