Ticket #10987: dj.patch

File dj.patch, 2.6 KB (added by redbaron, 6 years ago)
  • django/views/generic/list_detail.py

    
    diff --git a/django/views/generic/list_detail.py b/django/views/generic/list_detail.py
    index 27e36bd..07321d4 100644                                                         
    a b def object_detail(request, queryset, object_id=None, slug=None,  
    104104        slug_field='slug', template_name=None, template_name_field=None,             
    105105        template_loader=loader, extra_context=None,                                 
    106106        context_processors=None, template_object_name='object',                     
    107         mimetype=None):                                                              
     107        mimetype=None, handler404=None):                                             
    108108    """                                                                             
    109109    Generic detail of an object.                                                     
    110110                                                                                     
    def object_detail(request, queryset, object_id=None, slug=None,  
    124124    try:                                                                             
    125125        obj = queryset.get()
    126126    except ObjectDoesNotExist:
    127         raise Http404, "No %s found matching the query" % (model._meta.verbose_name)
     127        if handler404:
     128            t = template_loader.get_template(handler404)
     129            c = RequestContext(request)
     130            return HttpResponse(t.render(c), status=404, mimetype=mimetype)
     131        else:
     132            raise Http404, "No %s found matching the query" % (model._meta.verbose_name)
    128133    if not template_name:
    129134        template_name = "%s/%s_detail.html" % (model._meta.app_label, model._meta.object_name.lower())
    130135    if template_name_field:
  • docs/ref/generic-views.txt

    diff --git a/docs/ref/generic-views.txt b/docs/ref/generic-views.txt
    index 427ef91..a0e2de5 100644
    a b A page representing an individual object. 
    877877    * mimetype: The MIME type to use for the resulting document. Defaults
    878878      to the value of the DEFAULT_CONTENT_TYPE setting.
    879879
     880    * handler404: The full name of a template to use in rendering the
     881      404 error page if object does not exist. This lets you use custom error
     882      page for this type of objects. If handler404 isn't specified, this view
     883      will raise Http404 exception and standart 404 error page will be shown to user.
     884
    880885**Template name:**
    881886
    882887If template_name isn't specified, this view will use the template
Back to Top