[英]FLASK - The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again
I am running this site using Flask.我正在使用 Flask 运行这个站点。 When I run the script, the initial site (index.html) appears, and everything seems fine.当我运行脚本时,会出现初始站点 (index.html),一切似乎都很好。 However, when I click submit at the bottom of the page, I encounter this error "The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again."但是,当我单击页面底部的提交时,遇到此错误“在服务器上找不到请求的 URL。如果您手动输入了 URL,请检查您的拼写并重试。”
Could you please help me find the problem?你能帮我找出问题吗? The code for the main app is below.主应用程序的代码如下。
from flask import Flask, render_template, request
from flask_sqlalchemy import SQLAlchemy
app = Flask(__name__)
ENV = 'dev'
if ENV =='dev':
app.debug = True
app.config['SQLALCHEMY_DATABASEU_URI'] = 'postgresql://postgres:postgres@localhost/Jeopardy'
else:
app.debug = False
app.config['SQLALCHEMY_DATABASEU_URI'] = ''
#sapp.config.from_object(os.environ['APP_SETTINGS'])
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
db=SQLAlchemy(app)
class Jeo(db.Model):
__tablename__ = 'allc'
number = db.Column(db.Integer, primary_key=True)
category = db.Column(db.String())
question = db.Column(db.String())
answer = db.Column(db.String())
def __init(self,category,question,answer,number):
self.category = category
self.question = question
self.answer = answer
self.number = number
@app.route('/')
def index():
return render_template("index.html")
@app.route("/add")
def add():
category=request.args.get('category')
question=request.args.get('question')
answer=request.args.get('answer')
number=request.args.get('number')
try:
allc=Jeo(
category = category,
question = question,
answer = answer,
number = number
)
db.session.add(allc)
db.session.commit()
return " added. "
except Exception as e:
return(str(e))
@app.route("/add/form",methods=['GET', 'POST'])
def add_form():
if request.method == 'POST':
category=request.get('category')
question=request.get('question')
answer=request.get('answer')
number=request.get('number')
try:
allc=Jeo(
category = category,
question = question,
answer = answer,
number = number
)
db.session.add(allc)
db.session.commit()
return ("added. ")
except Exception as e:
return(str(e))
return render_template('index.html')
if __name__ == '__main__':
app.run()
And the code index.html code is:并且代码 index.html 代码为:
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device=width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="../static/style.css">
<title>Jeopardy</title>
</head>
<body>
<div class="="container">
<img src="../static/logo.png" alt="Jeopardy" class ="logo">
<!-- @todo - message-->
<form action = "/submit" methods="POST">
<div class = " form-group">
<h3>Jeopardy Question</h3>
<input
type = "text"
name = "Question"
placeholder= "Type the Jeopardy question here"
/>
</div>
<div class = " form-group">
<h3>Jeopardy Answer</h3>
<input
type = "text"
name = "Answer"
placeholder= "Type the Jeopardy Answer here"
/>
</div>
</form>
</div>
</body>
</html>
The problem exists here...The place where you have to write form action="add" you have written it as action="submit"问题就在这里......你必须写表单action =“add”的地方你已经把它写成action =“submit”
<form action = "/add" methods="POST">
<div class = " form-group">
<h3>Jeopardy Question</h3>
<input
type = "text"
name = "Question"
placeholder= "Type the Jeopardy question here"
/>
</div>
<div class = " form-group">
<h3>Jeopardy Answer</h3>
<input
type = "text"
name = "Answer"
placeholder= "Type the Jeopardy Answer here"
/>
</div>
</form>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.