我是新手。但是,如果沒有愚蠢的問題......這是我的。爲什麼我的電子郵件(在身體部分)不包含消息?django - render_to_string不工作
這裏是我的香脆代碼:
message = render_to_string('contact_template.txt', {'contact_name': contact_name, 'contact_email': contact_email, 'form_content': content}, context_instance=RequestContext(request))
email = EmailMessage("New contact form submission", message, "[email protected]" +'', ['[email protected]'], headers = {'Reply-To': contact_email })
email.send()
我真的很感激任何幫助..它的工作從上午9點,仍然沒有..
我的模板(contact_template.txt),(全我收到的郵件包含這一點,但沒有消息):
Contact Name:
Email:
Content:
和我的觀點:(我不得不說,這是嚇人的......)
from polls.forms import ContactForm
from django.core.mail import EmailMessage
from django.template import Context, Template, RequestContext
from django.shortcuts import render
from django.shortcuts import redirect
from django.core.mail import send_mail, BadHeaderError
from django.http import HttpResponse, HttpResponseRedirect
from django.template.loader import render_to_string, get_template
def index(request):
return HttpResponse("Hello, world. You're at the poll index.")
def contact(request):
form_class = ContactForm
# logic!
if request.method == 'POST':
form = form_class(data=request.POST)
if form.is_valid():
contact_name = request.POST.get('contact_name', '')
contact_email = request.POST.get('contact_email', '')
content = request.POST.get('content', '')
message = render_to_string('contact_template.txt', {'contact_name': contact_name, 'contact_email': contact_email, 'form_content': content}, context_instance=RequestContext(request))
email = EmailMessage("New contact form submission", message, "[email protected]" +'', ['[email protected]'], headers = {'Reply-To': contact_email })
email.send()
return redirect('contact')
return render(request, 'contact.html', {'form': form_class,})
歡迎來到SO Anna。你介意發佈你的模板+這個觀點嗎?代碼應該是最低限度完成任何人重現相同的問題 – MohitC
哦謝謝你回答(不能更快樂),她是: –
在哪裏?還在等待。您可以編輯您的主要問題發佈 – MohitC