Django email template encoding
up vote
0
down vote
favorite
I maked a view with a form, that should send message on user email, but i have a problev with encoding. My template have some kirillic letters, and if i try to send mail i get an error:
'ascii' codec can't encode characters in position 325-329: ordinal not in range(128)
If i change text in my template to english letters everything works.
View:
def index(request):
seos = SEO.objects.get(id__exact=1)
socs = Social_networks.objects.get(id__exact=1)
globs = globalapp.objects.get(id__exact=1)
index = Index.objects.get(id__exact=1)
form = ContactForm(request.POST)
formmm = ContactusForm(request.POST)
email = globalapp.objects.values_list('emailfb', flat=True).get(id=1)
if form.is_valid():
subject = form.cleaned_data['subject']
sender = form.cleaned_data['sender']
message = form.cleaned_data['message']
fille = form.cleaned_data['fille']
recepients = email
from_email, to = sender, recepients
html_content = loader.render_to_string('globalapp/chunks/email_tpl.html',
{'subject': subject, 'sender':sender, 'message':message, 'fille':fille})
msg = EmailMultiAlternatives(subject, html_content, from_email, [to])
msg.send()
if request.method == 'POST':
subject = request.POST['subject']
email = request.POST['sender']
message = request.POST['message']
form = 'Шапка'
post.objects.create(
subject = subject,
email = email,
message = message,
form = form
)
return HttpResponse('')
return render(request, 'globalapp/index.html', {'seos': seos,
'socs': socs,
'globs': globs,
'index': index,
'form': form,
'formmm': formmm })
Template:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<h2>Новое сообщение с сайта!</h2>
<p>Имя: {{ subject }}</p>
<p>Email: {{ sender }}</p>
<p>Сообщение: {{ message }}</p>
</html>
Ill tryed already to use .endoce('utf-8')
with template, but didnt get any results yet.
django python-3.x django-forms django-templates django-views
|
show 6 more comments
up vote
0
down vote
favorite
I maked a view with a form, that should send message on user email, but i have a problev with encoding. My template have some kirillic letters, and if i try to send mail i get an error:
'ascii' codec can't encode characters in position 325-329: ordinal not in range(128)
If i change text in my template to english letters everything works.
View:
def index(request):
seos = SEO.objects.get(id__exact=1)
socs = Social_networks.objects.get(id__exact=1)
globs = globalapp.objects.get(id__exact=1)
index = Index.objects.get(id__exact=1)
form = ContactForm(request.POST)
formmm = ContactusForm(request.POST)
email = globalapp.objects.values_list('emailfb', flat=True).get(id=1)
if form.is_valid():
subject = form.cleaned_data['subject']
sender = form.cleaned_data['sender']
message = form.cleaned_data['message']
fille = form.cleaned_data['fille']
recepients = email
from_email, to = sender, recepients
html_content = loader.render_to_string('globalapp/chunks/email_tpl.html',
{'subject': subject, 'sender':sender, 'message':message, 'fille':fille})
msg = EmailMultiAlternatives(subject, html_content, from_email, [to])
msg.send()
if request.method == 'POST':
subject = request.POST['subject']
email = request.POST['sender']
message = request.POST['message']
form = 'Шапка'
post.objects.create(
subject = subject,
email = email,
message = message,
form = form
)
return HttpResponse('')
return render(request, 'globalapp/index.html', {'seos': seos,
'socs': socs,
'globs': globs,
'index': index,
'form': form,
'formmm': formmm })
Template:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<h2>Новое сообщение с сайта!</h2>
<p>Имя: {{ subject }}</p>
<p>Email: {{ sender }}</p>
<p>Сообщение: {{ message }}</p>
</html>
Ill tryed already to use .endoce('utf-8')
with template, but didnt get any results yet.
django python-3.x django-forms django-templates django-views
Please indicate on which line the error occurs.
– dirkgroten
Nov 19 at 13:44
On linemsg.send()
– Andrej Vilenskij
Nov 19 at 13:46
if you open a django shell,from django.conf import settings
and printsettings.DEFAULT_CHARSET
what do you get?
– dirkgroten
Nov 19 at 13:52
>>> from django.conf import settings >>> settings.DEFAULT_CHARSET 'utf-8'
– Andrej Vilenskij
Nov 19 at 13:57
1
You're using the console email backend, maybe your console doesn't allow non-ascii output? Try using a proper email backend as you would in production (e.g. SMTP) and see if that works. If it does, then maybe change your code to differentiate between backends.
– dirkgroten
Nov 19 at 14:27
|
show 6 more comments
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I maked a view with a form, that should send message on user email, but i have a problev with encoding. My template have some kirillic letters, and if i try to send mail i get an error:
'ascii' codec can't encode characters in position 325-329: ordinal not in range(128)
If i change text in my template to english letters everything works.
View:
def index(request):
seos = SEO.objects.get(id__exact=1)
socs = Social_networks.objects.get(id__exact=1)
globs = globalapp.objects.get(id__exact=1)
index = Index.objects.get(id__exact=1)
form = ContactForm(request.POST)
formmm = ContactusForm(request.POST)
email = globalapp.objects.values_list('emailfb', flat=True).get(id=1)
if form.is_valid():
subject = form.cleaned_data['subject']
sender = form.cleaned_data['sender']
message = form.cleaned_data['message']
fille = form.cleaned_data['fille']
recepients = email
from_email, to = sender, recepients
html_content = loader.render_to_string('globalapp/chunks/email_tpl.html',
{'subject': subject, 'sender':sender, 'message':message, 'fille':fille})
msg = EmailMultiAlternatives(subject, html_content, from_email, [to])
msg.send()
if request.method == 'POST':
subject = request.POST['subject']
email = request.POST['sender']
message = request.POST['message']
form = 'Шапка'
post.objects.create(
subject = subject,
email = email,
message = message,
form = form
)
return HttpResponse('')
return render(request, 'globalapp/index.html', {'seos': seos,
'socs': socs,
'globs': globs,
'index': index,
'form': form,
'formmm': formmm })
Template:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<h2>Новое сообщение с сайта!</h2>
<p>Имя: {{ subject }}</p>
<p>Email: {{ sender }}</p>
<p>Сообщение: {{ message }}</p>
</html>
Ill tryed already to use .endoce('utf-8')
with template, but didnt get any results yet.
django python-3.x django-forms django-templates django-views
I maked a view with a form, that should send message on user email, but i have a problev with encoding. My template have some kirillic letters, and if i try to send mail i get an error:
'ascii' codec can't encode characters in position 325-329: ordinal not in range(128)
If i change text in my template to english letters everything works.
View:
def index(request):
seos = SEO.objects.get(id__exact=1)
socs = Social_networks.objects.get(id__exact=1)
globs = globalapp.objects.get(id__exact=1)
index = Index.objects.get(id__exact=1)
form = ContactForm(request.POST)
formmm = ContactusForm(request.POST)
email = globalapp.objects.values_list('emailfb', flat=True).get(id=1)
if form.is_valid():
subject = form.cleaned_data['subject']
sender = form.cleaned_data['sender']
message = form.cleaned_data['message']
fille = form.cleaned_data['fille']
recepients = email
from_email, to = sender, recepients
html_content = loader.render_to_string('globalapp/chunks/email_tpl.html',
{'subject': subject, 'sender':sender, 'message':message, 'fille':fille})
msg = EmailMultiAlternatives(subject, html_content, from_email, [to])
msg.send()
if request.method == 'POST':
subject = request.POST['subject']
email = request.POST['sender']
message = request.POST['message']
form = 'Шапка'
post.objects.create(
subject = subject,
email = email,
message = message,
form = form
)
return HttpResponse('')
return render(request, 'globalapp/index.html', {'seos': seos,
'socs': socs,
'globs': globs,
'index': index,
'form': form,
'formmm': formmm })
Template:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<h2>Новое сообщение с сайта!</h2>
<p>Имя: {{ subject }}</p>
<p>Email: {{ sender }}</p>
<p>Сообщение: {{ message }}</p>
</html>
Ill tryed already to use .endoce('utf-8')
with template, but didnt get any results yet.
django python-3.x django-forms django-templates django-views
django python-3.x django-forms django-templates django-views
asked Nov 19 at 13:22
Andrej Vilenskij
49110
49110
Please indicate on which line the error occurs.
– dirkgroten
Nov 19 at 13:44
On linemsg.send()
– Andrej Vilenskij
Nov 19 at 13:46
if you open a django shell,from django.conf import settings
and printsettings.DEFAULT_CHARSET
what do you get?
– dirkgroten
Nov 19 at 13:52
>>> from django.conf import settings >>> settings.DEFAULT_CHARSET 'utf-8'
– Andrej Vilenskij
Nov 19 at 13:57
1
You're using the console email backend, maybe your console doesn't allow non-ascii output? Try using a proper email backend as you would in production (e.g. SMTP) and see if that works. If it does, then maybe change your code to differentiate between backends.
– dirkgroten
Nov 19 at 14:27
|
show 6 more comments
Please indicate on which line the error occurs.
– dirkgroten
Nov 19 at 13:44
On linemsg.send()
– Andrej Vilenskij
Nov 19 at 13:46
if you open a django shell,from django.conf import settings
and printsettings.DEFAULT_CHARSET
what do you get?
– dirkgroten
Nov 19 at 13:52
>>> from django.conf import settings >>> settings.DEFAULT_CHARSET 'utf-8'
– Andrej Vilenskij
Nov 19 at 13:57
1
You're using the console email backend, maybe your console doesn't allow non-ascii output? Try using a proper email backend as you would in production (e.g. SMTP) and see if that works. If it does, then maybe change your code to differentiate between backends.
– dirkgroten
Nov 19 at 14:27
Please indicate on which line the error occurs.
– dirkgroten
Nov 19 at 13:44
Please indicate on which line the error occurs.
– dirkgroten
Nov 19 at 13:44
On line
msg.send()
– Andrej Vilenskij
Nov 19 at 13:46
On line
msg.send()
– Andrej Vilenskij
Nov 19 at 13:46
if you open a django shell,
from django.conf import settings
and print settings.DEFAULT_CHARSET
what do you get?– dirkgroten
Nov 19 at 13:52
if you open a django shell,
from django.conf import settings
and print settings.DEFAULT_CHARSET
what do you get?– dirkgroten
Nov 19 at 13:52
>>> from django.conf import settings >>> settings.DEFAULT_CHARSET 'utf-8'
– Andrej Vilenskij
Nov 19 at 13:57
>>> from django.conf import settings >>> settings.DEFAULT_CHARSET 'utf-8'
– Andrej Vilenskij
Nov 19 at 13:57
1
1
You're using the console email backend, maybe your console doesn't allow non-ascii output? Try using a proper email backend as you would in production (e.g. SMTP) and see if that works. If it does, then maybe change your code to differentiate between backends.
– dirkgroten
Nov 19 at 14:27
You're using the console email backend, maybe your console doesn't allow non-ascii output? Try using a proper email backend as you would in production (e.g. SMTP) and see if that works. If it does, then maybe change your code to differentiate between backends.
– dirkgroten
Nov 19 at 14:27
|
show 6 more comments
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53375573%2fdjango-email-template-encoding%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Please indicate on which line the error occurs.
– dirkgroten
Nov 19 at 13:44
On line
msg.send()
– Andrej Vilenskij
Nov 19 at 13:46
if you open a django shell,
from django.conf import settings
and printsettings.DEFAULT_CHARSET
what do you get?– dirkgroten
Nov 19 at 13:52
>>> from django.conf import settings >>> settings.DEFAULT_CHARSET 'utf-8'
– Andrej Vilenskij
Nov 19 at 13:57
1
You're using the console email backend, maybe your console doesn't allow non-ascii output? Try using a proper email backend as you would in production (e.g. SMTP) and see if that works. If it does, then maybe change your code to differentiate between backends.
– dirkgroten
Nov 19 at 14:27