Hello James Your suggestion worked.
Thank you very much for your help. Ron On Tuesday, September 5, 2017 at 10:04:04 PM UTC+1, James Schneider wrote: > > However, when I try to add the photo to the page I’m getting stuck. If I >> try adding ‘<img src…’ as in the following: >> >> >> {% block content %} >> <!-- 'index' from urls.py --> >> <a href="{% url 'indexurl' %}">< Back</a> >> {% if pht != None %} >> <h2>{{ pht.name }}</h2> >> <h4>{{ pht.location.name }}</h4> >> <p>{{ pht.description }}</p> >> <p>{{ pht.photo_taken }}</p> >> <img src={{ MEDIA_URL 'pht.photo_taken.name' }} class= >> "responsive-img" style='max-height:100px;' alt="face"> >> {% else %} >> <h1>Invalid item ID</h1> >> {% endif %} >> {% endblock %} >> >> >> …I get the following message (curly brackets and enclosed text were >> highlighted in red): >> Could not parse the remainder: ' 'pht.photo_taken.name'' from 'MEDIA_URL >> 'pht.photo_taken.name'' >> >> 28 <img src={{ MEDIA_URL 'pht.photo_taken.name' }} class="responsive-img" >> style='max-height:100px;' alt="face"> >> > > > > Note that {{ MEDIA_URL }} is strictly a variable reference and takes no > other inputs. You are treating it as a template tag, which are enclosed > using {% %}, hence the reason you are receiving this error. > > > >> >> >> I’m clearly missing one or two important steps but cannot seen them. Can >> anyone advise me on what I am doing wrong, please? >> >> >> >> Thanks >> >> >> >> Ron >> > > What you likely want is this: > > <img src="{{ pht.photo_taken.url }}" class="responsive-img" > style='max-height:100px;' alt="face"> > > (Note that the src= has " surrounding both variables, and that I'm using > pht.photo_taken.url rather than pht.photo_taken.name, which should only > be used to reference the actual file on disk per the docs.) > > https://docs.djangoproject.com/en/1.11/ref/models/fields/#imagefield > > https://docs.djangoproject.com/en/1.11/ref/models/fields/#django.db.models.FileField.storage > > Which should render to something like this: > > <img > src="/media/wildlifephotos/2017/07/26/2017-06-30_Lansdowne_-_Syrphus_Sp_A_01.JPG" > > class="responsive-img" style='max-height:100px;' alt="face"> > > I don't even think you need MEDIA_URL in your templates given the .url > shortcut provided by the ImageField model field. That's probably why > MEDIA_URL is not made available in the template by default: > > https://docs.djangoproject.com/en/1.11/ref/settings/#std:setting-MEDIA_URL > > -James > -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/ef10c206-5e33-4693-9509-82239c29bca1%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.