因此,我有一个简单的联系表,Django通过向我和与我们联系的人发送电子邮件来处理。我已经编写了一个AJAX函数来处理它。唯一的是,无论我尝试什么,我都会保持500身份。
我的Django(1.11)代码:
<?php
$jsondata = file_get_contents("saves.json.json");
$array_data = json_decode($jsondata, true);
$named_array = array(
"save2" => array(
array(
"health" => "100",
"coins" => "10",
"level" => "1"
)
)
);
array_push($array_data['saves'], $named_array);
$array_data['saves'] = $named_array;
$final_data = json_encode($array_data);
if(file_put_contents("test.json", $final_data, FILE_APPEND))
{
echo "0";
}
?>
这是我的AJAX请求:
def contato(request):
if request.method == 'POST':
name = request.POST['name']
email = request.POST['email']
phone = request.POST['phone']
message = request.POST['message']
newmessage = "Mensagem recebida de {}.\nTelefone: {}\ne-mail {}\n {}".format(name, phone, email, message)
send_mail(
'Nova mensagem pelo site',
newmessage,
'PLACEHOLDER@EMAIL',
['PLACEHOLDER@EMAIL'],
fail_silently=False
)
send_mail(
'Recebemos sua mensagem!',
'Olá, {}!\nRecebemos sua mensagem e entraremos em contato em breve.'.format(name),
'PLACEHOLDER@EMAIL',
[email],
fail_silently=False
)
return HttpResponse()
答案 0 :(得分:0)
只需将此问题标记为已解决:
在加载响应时,我必须运行.decode()
。现在一切正常。