Friday, June 16, 2017

Re: Images are not displaying

Hello,

<img src="static/images/logo.jpg" alt="My Logo"/>
This is probably missing a slash before "static"; it should be like this:

<img src="/static/images/logo.jpg" alt="My Logo"/>

But a better way is this:

{% load static %}

...

<img src="{% static 'images/logo.jpg' %}" alt="My Logo"/>

If you are on production rather than development, see also this: https://djangodeployment.com/2016/11/21/how-django-static-files-work-in-production/

Regards,

Antonis

Antonis Christofides  http://djangodeployment.com

On 2017-06-16 08:44, Santosh Yelamarthi wrote:
Hi,

am using django 1.10 version. am unable to display images in web.

my app name -- polls

I created templates directory and i put my home.html over there 
<html>
<body>
<img src="static/images/logo.jpg" alt="My Logo"/>
</div>
</body>
</html>

I created static folder and i put my image logo.jpg over there

In my views file I imported home.html :

from django.shortcuts import render_to_response
from django.http import HttpResponse

# Create your views here.
def index(request):
    return render_to_response('home.html')

settings.py :

STATIC_URL = '/static/'

I am able to display text but not images.


Can any one please help me in this.

Thanks in advance
--
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+unsubscribe@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/e3703e83-01d4-4412-9227-c82147262571%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment