1)。我有一个用户电子邮件的下拉列表。当我选择其中一个时,此电子邮件会出现模态窗口,我可以向该电子邮件发送消息。但是,当我发送它时,出现错误:'NoneType' object is not subscriptable
。问题是什么?我的对象不是空的。(我用ajax
得到了)我可以在控制台中收到我的电子邮件。
2)。第二个问题是我无法在页面上显示born_date
和phone_number
,但可以在控制台中打印它们。 render_template
有问题。请帮忙。
数据库结构:
@app.route('/profile', methods=['GET','POST'])
def profile():
if request.method == 'POST':
print('Holy Shit!')
data = request.json
print(str_value_to_list(data['selectedItems'][0]))
cur = mysql.connection.cursor()
cur.execute("SELECT born_date, phone_number FROM users.data WHERE email = '%s'" %
str_value_to_list(data['selectedItems'][0]))
account = cur.fetchone()
born = account[0]
num = account[1]
print(born)
print(num)
return render_template('profile.html', born=born, num=num)
html:
<form action="profile" method="POST" enctype="multipart/form-data">
<div class="container reg" style="width: 45%;">
<div class="form-wrapper">
<p class="white-text" style="color: #000;">Search your email</p>
<br>
<button type="button" class="btn btn-primary" onclick="process();" style="background:#3E75A5; border: 1px solid #285F8F;">
Get Info
</button>
<script type="text/javascript">
function printValue(selectedItem){
$('#mySelectedValue').html(selectedItem.value);
}
</script>
<div class="modal fade" id="exampleModalCenter" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLongTitle">Information about user</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<p class="form-control" id="mySelectedValue" style="margin-top: 10px;"></p>
<input type="text" name="text" class="form-control" placeholder="Add your message here" required="required">
<h2 class="white-text" style="font-size: 14px; color: #000;">born: {{ born }}</h2>
<h2 class="white-text" style="font-size: 14px; color: #000;">num: {{ num }}</h2>
<button class="btn btn-primary send">
Send
</button>
</div>
</div>
</div>
</div>
<script type="text/javascript">
function printValue(selectedItem) {
$('#mySelectedValue').html(selectedItem.value.replace(/[{()}]/g, '').replace(/['"]+/g, '').replace(/[{,}]/g, ''));
console.log(selectedItem.value);
}
function process(selectedItem) {
$('#exampleModalCenter').modal('show')
document.getElementById('#exampleModalCenter')
const data = JSON.stringify({
"selectedItems": $('#sel').val()
});
$.ajax({
url: "/profile",
type: "POST",
contentType: "application/json",
data: data,
success: function (data) {
console.log(data);
},
});
}
function optionClick(selectedItem) {
printValue(selectedItem);
}
</script>
</div>
</div>
</form>