[Answered ]-Displaying an image to sending email in django

2👍

First of all, it won’t work in localhost… The image won’t be attached to the email — what actually is gonna happen is the html in the email refer to the image in your server, e.g. (http://example.com/static/Kamal.png)

That been said, you can either set a full path STATIC_URL like:

STATIC_URL = 'http://example.com/static/'

Instead of just:

STATIC_URL = '/static/'

The other option is using the get_host() method to build your url, in case you have STATIC_URL = '/static/':

<img src="{{ request.get_host }}{% static 'Kamal.png' %}" alt=" Mon Image "/>

https://docs.djangoproject.com/en/1.9/ref/request-response/#django.http.HttpRequest.get_host

0👍

Send Domain Name Before Sending mail:

site=Site.objects.filter(id=1)
domain = site[0].domain //You will get your domain name 'xyz.com'
subject ="Conform your email address "
message = render_to_string('EmailTemplates/Email_verification.html', {
                    'email':user.email,
                    'user_display':user.first_name,
                    'domain':"{0}".format(domain),//It will return
                                    your doman 'http://127.0.0.1:8000 or etc'
                     })
                send_email(subject, message, user
)

Your Templates use Domain before static url:

<img src="{{domain}}/static/DataSearch/images/slider-image.png" alt="Party Wumpus" title="None" width="500" style="height: auto;">

Leave a comment