Opened 2 years ago

Closed 2 years ago

Last modified 2 years ago

#20042 closed Bug (invalid)

TemplateDoesNotExist when using DetailView with no template_name

Reported by: anonymous Owned by: nobody
Component: Uncategorized Version: 1.4
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I get a TemplateDoesNotExist when using DetailView with no template_name:

myapp/mymodel_detail.html

In urls.py

    url(r'^admin/<myapp>/<mymodel>/(?P<pk>\d+)/$', views.MyModelDetailView.as_view(), name='mymodel_detail'),
    url(r'^admin/', include(admin.site.urls)),
    ...

In models.py

    class MyModelDetailView(DetailView):

        model = MyModel

        def get(self, request, *args, **kwargs):
            try:
                self.model.objects.get(pk=kwargs['pk'])           
                return super(MyModelDetailView, self).get(request, **kwargs)
            except Http404:
                render_to_response('admin/no_object.html')

Change History (2)

comment:1 Changed 2 years ago by matiasb

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to invalid
  • Status changed from new to closed

This works as expected in 1.4 (and master too).
You may be missing some template dir setting?

comment:2 Changed 2 years ago by anonymous

I don't want to set any template. I want the default view/template when returning

super(MyModelDetailView, self).get(request, **kwargs)

. Is the template attribute required? I don't see any in the doc .

Note: See TracTickets for help on using tickets.
Back to Top