html - using static images with django -


i trying upload static images website django. have been through settings.py , in there should because static css works. question how code if product id 1 shown show picture. have tried code below images don't show up.

<!doctype html public "-//w3c//dtd xhtml 1.0 strict//en"         "http://www.w3.org/tr/xhtml1/dtd/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> {% load staticfiles %} <head>     <meta http-equiv="content-type" content="text/html;charset=utf-8" />     <title> book cove </title>     <link rel="stylesheet" type="text/css" href="{% static 'screenstyle.css' %}"/> </head>  <body>  <div id = "content">  <div id = "header"><p class="heading"> book cove.</p></div>  <div id="navbar">   <ul id="nav">     <li><a href="homepage.html" id="current">homepage</a></li>     <li><a href="{% url 'fiction_list' %}">non-fiction</a></li>     <li><a href="{% url 'nonfiction_list' %}">fiction</a></li>     <li><a href="contact.html">contact us</a></li>   </ul> </div>  <div id = "titleone"><h1>                {% if nonfiction %} fiction                   {% elif fiction %} non-fiction                           {% endif %}  </h1></div>  <div id = "productone"> {% if fiction %} <ul>      {% product in fiction %}     <li id="pname"><a href=" url 'product_detail' product.id%}">{{ product }}</a></li>     <p class="price"> £{{ product.price }}</p>     <p class="author"><em> {{ product.author }} </em></p><hr />         {% if pk.id = 1 %}         <img src="{% static 'cat1.png' %}" alt="fault in our stars" />         {% elif product.id = 2 %}         <img src="{% static 'cat2.png' %}" alt = "looking alaska" />         {% elif product.id = 3 %}         <img src="{% static 'cat3.png' %}" alt = "looking alaska" />         {% elif product.id = 4 %}         <img src="{% static 'cat4.png' %}" alt = "looking alaska" />         {% elif product.id = 5 %}         <img src="{% static 'cat5.png' %}" alt = "looking alaska" />         {% endif %}  {% endfor %} </ul>  {% elif nonfiction %}  <ul>      {% product in nonfiction %}         <li id="pname"><a href=" url 'product_detail' product.id%}">{{ product }}</a></li>     <p class ="price"> £{{ product.price }}</p>     <p class ="author"><em> {{ product.author }} </em></p><hr />      {% endfor %} </ul>  {% else %} <p> no products found!</p> {% endif %} </div>  <div id = "footer"><p><strong>copyright © 2011 book cove. rights reserved</strong></p></div>  </div>  </body> </html> 

you need using equality (==) instead of assignment (=)

{% if pk.id == 1 %} 

however, better way have imagefield on product model , template way simpler.

{% product in fiction %}     <li id="pname">       <a href=" url 'product_detail' product.id%}">{{ product }}</a>     </li>     <p class="price"> £{{ product.price }}</p>     <p class="author"><em> {{ product.author }} </em></p><hr />     <img src="{{ product.image.url }}" alt="looking alaska" /> {% endfor %} 

Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

[C++][SFML 2.2] Strange Performance Issues - Moving Mouse Lowers CPU Usage -

ios - Possible to get UIButton sizeThatFits to work? -