我试图允许用户将他们的gematria计算提交到一个文本文件中,这样我就可以在提交到数据库之前手动检查它们;因此,我在一个模式中放置了一个简单的表单,输入type=为“submit”,但我一直收到一个400错误的请求错误,我不知道为什么它不能工作。
我将Python3.6服务器端与flask结合使用,而不是将bootstrap与html结合使用。
服务器端:
if request.form["action"] == "Send":
Name = request.form["name"]
Email = request.form["mail"]
GematriaNum = request.form["gematria"]
Source = request.form["source"]
Calc = request.form["calc"]
LIT = request.form["transliteration"]
LANGY = request.form["translation"]
NEWSL = request.form["newsletter"]
BODYOF = Name + Email + GematriaNum + Source + Calc + LIT + LANGY + NEWSL
with open("submiss.txt", "w") as submiss:
submiss.write(BODYOF)
return render_template("index.html")
return redirect(url_for('index'))
网页代码:
<!-- ...it's part of a nav bar. -->
<!-- Trigger/Open The Modal -->
<li><a id="myBtn">Submit your Calculations to the Database!</a></li>
</ul>
<!-- The Modal -->
<div id="myModal" class="modal">
<!-- Modal content -->
<div class="modal-content">
<span class="close">×</span>
<form action="." method="POST"><span>
Name:<br>
<textarea style="resize:none" name="name" cols="25" rows="1" maxlength="25"></textarea><br>
E-mail:<br>
<textarea style="resize:none" name="mail" cols="25" rows="1" maxlength="25"></textarea><br>
Gematria Number:<br>
<textarea style="resize:none" name="gematria" cols="25" rows="1" maxlength="25"></textarea><br>
Source Text [i.e. Exodus 2:12]:<br>
<textarea style="resize:none" name="source" cols="25" rows="1" maxlength="25"></textarea><br>
Calculation in Hebrew, Greek or English:<br>
<textarea style="resize:none" name="calc" cols="50" rows="1" maxlength="100"></textarea><br>
Transliteration (if applicable):<br>
<textarea style="resize:none" name="transliteration" cols="50" rows="1" maxlength="100"></textarea><br>
Meaning and Usage:<br>
<textarea style="resize:none" name="translation" cols="50" rows="1" maxlength="100"></textarea><br>
<br>
<input type="checkbox" checked="checked" name="newsletter" style="margin-bottom:15px"> Sign up for our newsletter?<br>
<input type="submit" value="Send"></span>
<input type="reset" value="Reset">
</form>
<br>
Thanks!
</div>
</div>
<script>
// Get the modal
var modal = document.getElementById('myModal');
// Get the button that opens the modal
var btn = document.getElementById("myBtn");
// Get the <span> element that closes the modal
var span = document.getElementsByClassName("close")[0];
// When the user clicks the button, open the modal
btn.onclick = function() {
modal.style.display = "block";
}
// When the user clicks on <span> (x), close the modal
span.onclick = function() {
modal.style.display = "none";
}
// When the user clicks anywhere outside of the modal, close it
window.onclick = function(event) {
if (event.target == modal) {
modal.style.display = "none";
}
}
</script>
您可以查看该网站的实时here。
希望你能帮上忙。
https://stackoverflow.com/questions/50725371
复制相似问题