Ben bir acemiim. Ama, eğer aptalca sorular olmasaydı ... işte benim. Neden e-postam (gövde kısmında) iletiyi içermiyor? 9 am ve hala yoktan üzerinde çalışıyoruz .. Gerçekten herhangi bir yardım takdir ediyorumdjango - render_to_string çalışmıyor
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()
.. tüm
Benim şablonu (contact_template.txt), (: İşte
benim gevrek kodudur benim alınan e-postalar bu içeriyordu, ancak hiçbir ileti):Contact Name:
Email:
Content:
ve görüşlerim: (ı ... korkutucu olduğunu söylemek zorunda)
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'ya hoş geldiniz. Bunun için şablon + görünümünüzü yayınlamak ister misiniz? Kod aynı sorunu – MohitC
çoğaltmak herkes için minimal olmalıdır. Cevap için teşekkür ederim (daha mutlu olamazdı), o: –
Nerede? Hala bekliyor. Asıl meselenizi düzenleyebilir – MohitC