InterviewSolution
| 1. |
How Can I Write A Widget Which Displays An Image? |
|
Answer» That’s easy. Just include an image TAG in the template of the widget: class ImageWidget(widgets.Widget): template = '<img xmlns:py="HTTP://purl.org/kid/ns#" SRC="${VALUE}" />' and provide the image URL when you display the widget: ${myimagewidget(tg.url('myimage.png'))} If you want to serve a dynamically generated image, you have to provide a controller method for this, and use the URL to this controller method as the value for the widget. That’s easy. Just include an image tag in the template of the widget: class ImageWidget(widgets.Widget): template = '<img xmlns:py="http://purl.org/kid/ns#" src="${value}" />' and provide the image URL when you display the widget: ${myimagewidget(tg.url('myimage.png'))} If you want to serve a dynamically generated image, you have to provide a controller method for this, and use the URL to this controller method as the value for the widget. |
|