2016-05-24 7 views
0

HTMLコンテンツに画像が含まれていて表示されない場合、送信されたHTMLメールを含むメールを送信したいと思います。 さらに、ローカルピクチャのHTMLテンプレートを表示しようとすると正しく表示されます。 イメージをHTMLコンテンツに表示する方法は?djangoでメールを送信する画像を表示する

HTMLコンテンツ

<!DOCTYPE html> 
{% load static %} 
<html lang="en"> 
<head> 
    <style> 
     body{ 
      background-color: gray; 
      color: red; 
     } 
     div, #globale{ 
      background-color:#eee; 
     } 
    </style> 
</head> 
<body> 
     <!--<img src=" {% static "Kamal.png" %}" alt="image"/>--> 
     <!-<img src="{% static "Kamal.png" %}" alt="image"/>--> 
     <div id="globale"> 
      <p> 
       Convert the filename, content, mimetype triple into a MIME attachment 
       object. Adjust headers to use Content-ID where applicable. 
       Taken from <img src="Kamal.png" alt=" Mon Image "/> 
       HTML is the method of choice for those wishing to send emails with rich 
       text, layout and graphics. Often it is desirable to embed the graphics 
       within the message so recipients can display the message directly, 
       without further downloads. 
       <img src="{% static "Kamal.png" %}" alt=" Mon Image "/> 
       Some mail agents don't support HTML or their users prefer to receive 
       plain text messages. Senders of HTML messages should include a plain 
       text message as an alternate for these users. 
       <img src="Kamal.png" /> 
       This recipe sends a short HTML message with a single embedded image 
       and an alternate plain text message. 
      </p> 
      <h3>Message Reussi avec Image</h3> 
     </div> 
</body> 
</html> 
+0

あなたは 'STATIC_URL'変数には何がありますか? – inlanger

+0

私のSTATIC_URL変数に私はこのSTATIC_URL = '/ static /'を持っています。 –

答えて

1

まず第一に、それはlocalhostの...画像を電子メールに添付されることはありませんでは動作しません - どのような実際つもり起きるれることでhtmlです電子メールはあなたのサーバーの画像を参照します。他のオプションは、あなたを構築するためにget_host()メソッドを使用している

STATIC_URL = '/static/' 

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

の代わりにちょうど:のように言われて、あなたは完全なパスSTATIC_URLを設定するか(http://example.com/static/Kamal.png

あなたが持っている場合のURL 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

返信ありがとうございますが、幸いにも私はローカルでそれをテストします http:// localhost:8000/static/Kamal.png画像は正しく表示されます 変数STATIC_URLを 'http:// localhost:8000/static /'に置き換えます.STATIC変数の表示URLを変更すると、 –

+0

は変更されません。 –

0

メールを送信する前にドメイン名を送信:

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 
) 

あなたのテンプレートは、静的なURLの前にドメインを使用します。

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