--
Ticket URL: <https://code.djangoproject.com/ticket/16502>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0
Comment:
Actually, this is a crash of the debug view itself.
When Django encounters a `TemplateDoesNotExist` exception, the debug view
attempts to gather information about available template loaders and
templates. It relies on the fact that
`django.template.loaders.template_source_loaders` is already populated (by
`django.template.loaders.find_template`). But in your case, it isn't. So a
new exception is raised, it overrides the initial exception, and —
unfortunately — it makes it difficult to understand what really happens
here.
--
Ticket URL: <https://code.djangoproject.com/ticket/16502#comment:1>
* status: new => assigned
* owner: nobody => Silver_Ghost
* stage: Unreviewed => Accepted
Comment:
''aaugustin'', through information from your comment I was able to find
possible place in code where additional check could be perfomed. It is
`django.template.loader.select_template` function.
It expects list of template names and select first loadable. If there are
some template names in list and no one from them couldn't be loaded then
raising `TemplateDoesNotExist` exception is the right decision since. But
if there isn't any template names in the list then
>>Template<<DoesNotExist is wrong exception, I think.
So maybe checks if list is empty and raise exception with message like "I
can't load any template for you because you didn't gave me any possible
variants"?
--
Ticket URL: <https://code.djangoproject.com/ticket/16502#comment:2>
* has_patch: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/16502#comment:3>
* version: 1.3 => SVN
--
Ticket URL: <https://code.djangoproject.com/ticket/16502#comment:4>
* cc: anton@… (added)
--
Ticket URL: <https://code.djangoproject.com/ticket/16502#comment:5>
* cc: bhuztez (added)
Comment:
function-based generic view,
`django.views.generic.create_update.create_object`, use default template
if no template_name is given. When you switch to class-based view,
`CreateView` will not work as you has expected, since
`django.views.generic.edit.CreateView` has no default template. This must
be a bug, please give `CreateView` a default template in 1.3.
--
Ticket URL: <https://code.djangoproject.com/ticket/16502#comment:6>
* cc: tinodb (added)
* needs_tests: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/16502#comment:7>
* needs_tests: 1 => 0
Comment:
I've merged my and ''bhustez'' 's patches and added regression tests for
both.
--
Ticket URL: <https://code.djangoproject.com/ticket/16502#comment:8>
* cc: preston@… (added)
--
Ticket URL: <https://code.djangoproject.com/ticket/16502#comment:9>
* needs_better_patch: 0 => 1
Comment:
There are too many issues being addressed here in one patch.
The ticket is valid and seeks the addition of a default template to
CreateView
Patches addressing how the template loader works, or a missing get_model
method on SingleObjectMixin should have their own tickets opened and
patches submitted.
--
Ticket URL: <https://code.djangoproject.com/ticket/16502#comment:10>
* needs_better_patch: 1 => 0
* easy: 0 => 1
Comment:
According to [https://groups.google.com/d/topic/django-
developers/jCsXf3eEqb4/discussion this discussion] patch for
`select_template` was separated to ticket:16866. Patch with `get_model`
was left here since there are multiple ways to define which model should
be used (the self.model, self.queryset or self.form_class attributes) and
it justifies having a utility function for it.
Tests provided.
--
Ticket URL: <https://code.djangoproject.com/ticket/16502#comment:11>
Comment (by charettes):
Just hit this issue, any chances this get attention for 1.4?
--
Ticket URL: <https://code.djangoproject.com/ticket/16502#comment:12>
Comment (by bhuztez):
update Silver_Ghost's patch for revision 17517
--
Ticket URL: <https://code.djangoproject.com/ticket/16502#comment:13>
* status: assigned => new
* owner: Silver_Ghost => aaugustin
--
Ticket URL: <https://code.djangoproject.com/ticket/16502#comment:14>
Comment (by bhuztez):
my pull request: https://github.com/django/django/pull/177
--
Ticket URL: <https://code.djangoproject.com/ticket/16502#comment:15>
* needs_better_patch: 0 => 1
Comment:
I don't like the way this patch/pull request works with ModelForms - it
magically extracts a model from a ModelForm, which already needs
discussion as it's new behaviour, but even worse it then passes that model
out and then makes a brand new ModelForm out of it - that shouldn't
happen.
--
Ticket URL: <https://code.djangoproject.com/ticket/16502#comment:16>
Comment (by bhuztez):
> I don't like the way this patch/pull request works with ModelForms - it
magically extracts a model from a ModelForm, which already needs
discussion as it's new behaviour
Yes, but it is not a new behaviour, the function-based generic view
counterpart did the same magic. I did not know whether or not the design
decision had been changed to not providing a default `template_name`. To
provide a default `template_name`, I don't think there is a much less
magical way , given current ModelForm API.
https://github.com/django/django/blob/stable/1.4.x/django/views/generic/create_update.py#L29
> but even worse it then passes that model out and then makes a brand new
ModelForm out of it - that shouldn't happen.
No, it does not. If `form_class` already exists, it will NOT make a new
`ModelForm` from `model` extracted from that, it will just return
`form_class` you defined. The function-based generic view counterpart did
the same.
--
Ticket URL: <https://code.djangoproject.com/ticket/16502#comment:17>
* owner: aaugustin => nobody
--
Ticket URL: <https://code.djangoproject.com/ticket/16502#comment:18>
* owner: nobody => krak3n
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/16502#comment:19>
* status: assigned => closed
* needs_better_patch: 1 => 0
* resolution: => worksforme
Comment:
I was unable to duplicate this in 1.5.1.
I created a basic model as below:
{{{
#!div style="font-size: 80%"
#models.py
}}}
{{{#!python
from django.db import models
class Author(models.Model):
name = models.CharField(max_length=100)
}}}
A basic view:
{{{
#!div style="font-size: 80%"
#views.py
}}}
{{{#!python
from django.views.generic import CreateView
from .models import Author
class CreateAuthor(CreateView):
model = Author
}}}
The traceback I got back was:
{{{
TemplateDoesNotExist at /
test_16502/author_form.html
Request Method: GET
Request URL: http://10.10.10.10:9000/
Django Version: 1.5.1
Exception Type: TemplateDoesNotExist
Exception Value:
test_16502/author_form.html
Exception Location:
/home/vagrant/django/django/django/template/loader.py in select_template,
line 194
Python Executable: /home/vagrant/.virtualenvs/django/bin/python
Python Version: 2.7.3
}}}
I think this is the correct exception that should be raised and the
exception is present in the regular debug view.
Perhaps this was an issue with earlier versions of Django and it's been
resolved in another ticket, though I can't hunt this down. Perhaps related
to ticket:16866?
Perhaps if this is still a bug provide more information on how to
reproduce it.
--
Ticket URL: <https://code.djangoproject.com/ticket/16502#comment:20>
* status: closed => new
* resolution: worksforme =>
Comment:
set `form_class` rather than `model`
https://code.djangoproject.com/attachment/ticket/16502/get_model_with_tests.3.diff#L168
--
Ticket URL: <https://code.djangoproject.com/ticket/16502#comment:21>
* needs_better_patch: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/16502#comment:22>
Comment (by magicharshit):
Replying to [comment:22 timo]:
--
Ticket URL: <https://code.djangoproject.com/ticket/16502#comment:23>
Comment (by jambonrose):
This is all a little convoluted. There is no longer one problem at hand,
and a little clarification might be useful.
Bug 1: `get_template_names()` (as defined in
`SingleObjectTemplateResponseMixin`) is returning `None`, which is causing
Django to throw a `TemplateDoesNotExist`. This should instead throw a
`ImproperlyConfigured` error, as it does not have the information to
determine the template file to load. This is more eloquently described in
#18853 (marked as duplicate to this topic)
Bug 2: The `TemplateDoesNotExist` exception is causing the server error
message, as detailed (and solved) in #21058.
Feature Request 1: Creating a CBGV by only overriding the `form_class`
variable. The patch provided creates the ability to do so, but does not
actually solve the bugs detailed.
I spoke to Russel about the possibility of the new feature. Unfortunately,
determining the model based off a form specified in `form_class` is not
desirable, because this assumes the form is a ModelForm, which may not be
the case. As such, this feature (and patch) will therefore not be approved
for Django.
This leaves only Bug 1 to be solved.
--
Ticket URL: <https://code.djangoproject.com/ticket/16502#comment:24>
* cc: ianawilson (added)
* needs_better_patch: 1 => 0
* status: new => assigned
* owner: krak3n => ianawilson
Comment:
Here is a pull request to fix Bug 1, as described by @jambonrose.
https://github.com/django/django/pull/1580
--
Ticket URL: <https://code.djangoproject.com/ticket/16502#comment:25>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"9b2dc12b8332389d1bfb9e83123a088a084a6a47"]:
{{{
#!CommitTicketReference repository=""
revision="9b2dc12b8332389d1bfb9e83123a088a084a6a47"
Merge pull request #1580 from ianawilson/ticket_16502
Fixed #16502 -- Fixed a TemplateDoesNotExist error that should be an
ImproperlyConfigured.
Assistance on the patch from #jambronrose.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/16502#comment:26>
Comment (by Russell Keith-Magee <russell@…>):
In [changeset:"99952bab3008622b05613ed6ec54c3e1c63c0a1d"]:
{{{
#!CommitTicketReference repository=""
revision="99952bab3008622b05613ed6ec54c3e1c63c0a1d"
[1.6.x] Merge pull request #1580 from ianawilson/ticket_16502
Fixed #16502 -- Fixed a TemplateDoesNotExist error that should be an
ImproperlyConfigured.
Assistance on the patch from #jambronrose.
Backport of 9b2dc12b8332389d1bfb9e83123a088a084a6a47 from master.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/16502#comment:27>
* status: closed => new
* resolution: fixed =>
Comment:
> determining the model based off a form specified in `form_class` is not
desirable, because this assumes the form is a ModelForm, which may not be
the case.
`CreateView` inherits `ModelFormMixin`. This already assumes form is a
ModelForm.
--
Ticket URL: <https://code.djangoproject.com/ticket/16502#comment:28>
* status: new => closed
* resolution: => fixed
Comment:
@bhuztez I'm going to re-close this and ask that you please open a new
ticket since we try to have one issue per ticket. I think the feature
request and patch look reasonable, but it's a bit difficult to follow the
conversation. Could you please a new ticket that summarizes the details
and include the most recent patch? I think the existing patch also needs
documentation. Thanks!
--
Ticket URL: <https://code.djangoproject.com/ticket/16502#comment:29>