Since I've upgraded to Django ver 1.00, I'm suddenly getting the
following error with my ImageFields.
The tag is {{ model.image.url}} and it throws an error if the image
field in the database is null (even if it is set to null in the model)
Am I missing something? Here is the error message being generated.
TemplateSyntaxError at /offer_detail_ver2/1/
Caught an exception while rendering: The 'image' attribute has no file
associated with it.
Original Traceback (most recent call last):
File "C:\Python25\Lib\site-packages\django-trunk\django\template
\debug.py", line 71, in render_node
result = node.render(context)
File "C:\Python25\Lib\site-packages\django-trunk\django\template
\debug.py", line 87, in render
output = force_unicode(self.filter_expression.resolve(context))
File "C:\Python25\Lib\site-packages\django-trunk\django\template
\__init__.py", line 535, in resolve
obj = self.var.resolve(context)
File "C:\Python25\Lib\site-packages\django-trunk\django\template
\__init__.py", line 676, in resolve
value = self._resolve_lookup(context)
File "C:\Python25\Lib\site-packages\django-trunk\django\template
\__init__.py", line 705, in _resolve_lookup
current = getattr(current, bit)
File "C:\Python25\Lib\site-packages\django-trunk\django\db\models
\fields\files.py", line 58, in _get_url
self._require_file()
File "C:\Python25\Lib\site-packages\django-trunk\django\db\models
\fields\files.py", line 43, in _require_file
raise ValueError("The '%s' attribute has no file associated with
it." % self.field.name)
ValueError: The 'image' attribute has no file associated with it.
Caught an exception while rendering: The 'image' attribute has no file
associated with it.
Original Traceback (most recent call last):
File "C:\Python25\Lib\site-packages\django-trunk\django\template
\debug.py", line 71, in render_node
result = node.render(context)
File "C:\Python25\Lib\site-packages\django-trunk\django\template
\debug.py", line 87, in render
output = force_unicode(self.filter_expression.resolve(context))
File "C:\Python25\Lib\site-packages\django-trunk\django\template
\__init__.py", line 535, in resolve
obj = self.var.resolve(context)
File "C:\Python25\Lib\site-packages\django-trunk\django\template
\__init__.py", line 676, in resolve
value = self._resolve_lookup(context)
File "C:\Python25\Lib\site-packages\django-trunk\django\template
\__init__.py", line 705, in _resolve_lookup
current = getattr(current, bit)
File "C:\Python25\Lib\site-packages\django-trunk\django\db\models
\fields\files.py", line 58, in _get_url
self._require_file()
File "C:\Python25\Lib\site-packages\django-trunk\django\db\models
\fields\files.py", line 43, in _require_file
raise ValueError("The '%s' attribute has no file associated with
it." % self.field.name)
ValueError: The 'image' attribute has no file associated with it.
C:\Python25\Lib\site-packages\django-trunk\django\template\debug.py in
render_node
> Since I've upgraded to Django ver 1.00, I'm suddenly getting the
> following error with my ImageFields.
> The tag is {{ model.image.url}} and it throws an error if the image
> field in the database is null (even if it is set to null in the model)
> Am I missing something? Here is the error message being generated.
> TemplateSyntaxError at /offer_detail_ver2/1/
> Caught an exception while rendering: The 'image' attribute has no file
> associated with it.
> Original Traceback (most recent call last):
> File "C:\Python25\Lib\site-packages\django-trunk\django\template
> \debug.py", line 71, in render_node
> result = node.render(context)
> File "C:\Python25\Lib\site-packages\django-trunk\django\template
> \debug.py", line 87, in render
> output = force_unicode(self.filter_expression.resolve(context))
> File "C:\Python25\Lib\site-packages\django-trunk\django\template
> \__init__.py", line 535, in resolve
> obj = self.var.resolve(context)
> File "C:\Python25\Lib\site-packages\django-trunk\django\template
> \__init__.py", line 676, in resolve
> value = self._resolve_lookup(context)
> File "C:\Python25\Lib\site-packages\django-trunk\django\template
> \__init__.py", line 705, in _resolve_lookup
> current = getattr(current, bit)
> File "C:\Python25\Lib\site-packages\django-trunk\django\db\models
> \fields\files.py", line 58, in _get_url
> self._require_file()
> File "C:\Python25\Lib\site-packages\django-trunk\django\db\models
> \fields\files.py", line 43, in _require_file
> raise ValueError("The '%s' attribute has no file associated with
> it." % self.field.name)
> ValueError: The 'image' attribute has no file associated with it.
> Caught an exception while rendering: The 'image' attribute has no file
> associated with it.
> Original Traceback (most recent call last):
> File "C:\Python25\Lib\site-packages\django-trunk\django\template
> \debug.py", line 71, in render_node
> result = node.render(context)
> File "C:\Python25\Lib\site-packages\django-trunk\django\template
> \debug.py", line 87, in render
> output = force_unicode(self.filter_expression.resolve(context))
> File "C:\Python25\Lib\site-packages\django-trunk\django\template
> \__init__.py", line 535, in resolve
> obj = self.var.resolve(context)
> File "C:\Python25\Lib\site-packages\django-trunk\django\template
> \__init__.py", line 676, in resolve
> value = self._resolve_lookup(context)
> File "C:\Python25\Lib\site-packages\django-trunk\django\template
> \__init__.py", line 705, in _resolve_lookup
> current = getattr(current, bit)
> File "C:\Python25\Lib\site-packages\django-trunk\django\db\models
> \fields\files.py", line 58, in _get_url
> self._require_file()
> File "C:\Python25\Lib\site-packages\django-trunk\django\db\models
> \fields\files.py", line 43, in _require_file
> raise ValueError("The '%s' attribute has no file associated with
> it." % self.field.name)
> ValueError: The 'image' attribute has no file associated with it.
> C:\Python25\Lib\site-packages\django-trunk\django\template\debug.py in
> render_node
On Thu, Feb 19, 2009 at 7:30 AM, mermer <merme...@googlemail.com> wrote:
> Since I've upgraded to Django ver 1.00, I'm suddenly getting the > following error with my ImageFields.
> The tag is {{ model.image.url}} and it throws an error if the image > field in the database is null (even if it is set to null in the model)
> Am I missing something? Here is the error message being generated.
> TemplateSyntaxError at /offer_detail_ver2/1/
> Caught an exception while rendering: The 'image' attribute has no file > associated with it.
There was some major file storage refactoring done before 1.0, which I'd guess introduced a requirement that attempting to retrieve the url associated with a file-type object requires a file to be associated with that object. A little experimenting in the shell shows that now where {{ m.file.url }} generates the exception you report in the case where m.file has no file,
{% if m.file %}{{ m.file.url }}{% endif %}
does not. I didn't work on the file storage refactor so I don't know if this was an intentional difference, and I haven't checked if this was explicitly documented as a backwards-incompatible change, but it seems not-so-surprising that such a method would require a file to be set, and easy enough to adjust to?