Note that there are some explanatory texts on larger screens.

plurals
  1. POFunction not being called in Python, why? and how can I solve it?
    text
    copied!<p>I am currently working on python/django site, at the moment I have a template that looks like this</p> <pre><code> {% extends "shopbase.html" %} {% block pageid %}products{% endblock %} {% block right-content %} &lt;img src="{{MEDIA_URL}}/local/images/assets/products.png" alt="Neal and Wolf News" class="position"/&gt; &lt;div class="products"&gt; &lt;form method="post" action="{% url category category.slug %}"&gt; {% for product in category.products.all %} &lt;div class="{% cycle 'clear' '' '' %}"&gt; &lt;img src="{{MEDIA_URL}}{{download.mini.thumbnail}}" alt="{{product.name}}" class="thumbnail"/&gt; &lt;h3&gt;&lt;a href="{% url shop.views.product category.slug product.slug %}"&gt;{{ product.product_type_name }}&lt;/a&gt;&lt;/h3&gt; &lt;p class="strap"&gt;{{ product.product_sub_name }}&lt;/p&gt; &lt;p&gt;{{ product.strap }}&lt;/p&gt; &lt;ul class="clear"&gt; &lt;li class="price"&gt;&lt;b&gt;&amp;pound;{{product.price}}&lt;/b&gt;&lt;/li&gt; &lt;li class="quantity"&gt; &lt;select name="quantity_{{product.id}}"&gt; &lt;option label="1" value="1"&gt;1&lt;/option&gt; &lt;option label="2" value="2"&gt;2&lt;/option&gt; &lt;option label="3" value="3"&gt;3&lt;/option&gt; &lt;option label="4" value="4"&gt;4&lt;/option&gt; &lt;option label="5" value="5"&gt;5&lt;/option&gt; &lt;option label="6" value="6"&gt;6&lt;/option&gt; &lt;option label="7" value="7"&gt;7&lt;/option&gt; &lt;option label="8" value="8"&gt;8&lt;/option&gt; &lt;option label="9" value="9"&gt;9&lt;/option&gt; &lt;/select&gt; &lt;/li&gt; &lt;li&gt;&lt;b&gt;&lt;a href="details"&gt;Details &amp;gt;&lt;/a&gt;&lt;/b&gt;&lt;/li&gt; &lt;li&gt;&lt;input type="submit" name="add_to_basket_{{product.id}}" value="Add to Basket &amp;gt;"/&gt;&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; {% endfor %} &lt;/form&gt; &lt;/div&gt; {% endblock %} </code></pre> <p>and in the model I have a class that looks like this</p> <pre><code>def get_thumbnail(self, dimension, on=RES_X, use=USE_BOTH): """ Generate a thumbnail image for this Store Object. The thumbnail will be of size 'dimension' on the axis specified by the on parameter (which is deduced from calling x_or_y). If the use parameter is set to USE_BOTH then the thumbnail will take priority in the generation order. In other words, the function checks for the existance of an uploaded thumbnail. If one exists, it will use that, otherwise the image field is used instead. Specifying either USE_IMAGE or USE_THUMBNAIL here will force the generation to a particular asset. The image is saved out as a jpeg with the quality set to 90. The path relative to the MEDIA_ROOT is then returned. """ from PIL import Image import os if self.thumbnail and use != StoreObject.USE_IMAGE: source_path = str(self.thumbnail) elif self.image and use != StoreObject.USE_THUMBNAIL: source_path = str(self.image) else: return "" try: against = StoreObject.x_or_y(on) except KeyError: return "" target_path = os.path.join(StoreObject.GENERATED_THUMB_LOCATION, "%s-%d%s.png" % (self.slug, dimension, against)) savepath = os.path.join(settings.MEDIA_ROOT, target_path) loadpath = os.path.join(settings.MEDIA_ROOT, source_path) if os.path.exists(savepath) and os.path.getmtime(savepath) &gt; os.path.getmtime(loadpath): return target_path try: img = Image.open(loadpath) except IOError: return "" aspect = float(img.size[0]) / float(img.size[1]) if against == StoreObject.RES_X: height = dimension / aspect width = dimension elif against == StoreObject.RES_Y: width = dimension * aspect height = dimension img = img.resize((width,height), Image.ANTIALIAS) img.convert('RGBA').save(savepath, "PNG") return target_path def mini_thumbnail(self): """ Generate and return the path to, a thumbnail that is 50px high """ return self.get_thumbnail(50, "x") def preview_image(self): """ Generate and return the path to, a thumbnail that is 300px wide, build from the image field """ return self.get_thumbnail(300, use=StoreObject.USE_IMAGE) def preview_thumbnail(self): """ Generate and return the path to, a thumbnail that is 300px wide, build from the thumbnail field """ return self.get_thumbnail(300, use=StoreObject.USE_THUMBNAIL) </code></pre> <p>Now as you can see I am trying to pull out of the database some information on a certain item, and show an image of that item in a thumbnail which generated from the thumbnail function above (in the template I using product.mini_thumbnail however there seems to be know image? however if I print product.image with my MEDIA_URL then I get the fullsized image. Can anyone suggest what might be happening?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload