6

in a simple django-tables2 how can i render an imagen in specific cell for 1 colum....

some like

   field1     field2   field3    .   .   .

row1 A image1 C

row2 B image2 D

. . .

Nathaniel
  • 666
  • 4
  • 15
emper0r
  • 63
  • 1
  • 3
  • I'm not clear what you're asking. Where does the image come from? Is it on a model? Might be worth adding the model code (plus any code you have for your table or your view) – Aidan Ewen Feb 07 '13 at 20:17
  • Is it polite at SO to write down "RTFM" at Answers? – n3storm Mar 15 '13 at 11:38
  • 1
    @n3storm That's not polite anywhere, but pointing out where in the docs to look (like you did in your answer) can be very helpful! Especially for a new user, documentation can be overwhelming. – thumbtackthief Oct 18 '13 at 18:33

1 Answers1

6

At Django Tables2 documentation:

http://django-tables2.readthedocs.org/en/latest/#subclassing-column

Example of this section is ImageColumn.

For complicated columns, you may want to return HTML from the render() method. This is fine, but be sure to mark the string as safe to avoid it being escaped:

>>> from django.utils.safestring import mark_safe
>>> from django.utils.html import escape
>>>
>>> class ImageColumn(tables.Column):
...     def render(self, value):
...         return mark_safe('<img src="/media/img/%s.jpg" />'
...                          % escape(value))
...

Link to official documentation: https://github.com/bradleyayers/django-tables2/blob/master/docs/index.rst (just in case)

n3storm
  • 704
  • 8
  • 21
  • 2
    When linking to an external source as an answer, be sure to always provide the important information of that source along with your answer. Links can die. – Lukas Knuth Mar 15 '13 at 11:54