英文:
Why, in Flask, am I getting an Internal Server Error if my code was working before?
问题
I'm trying to make an app & it's my first time using Flask. I've been writing my website in html and running it through the python I set up with Flask. My website was working fine for a month and a half, but now I keep getting an error every time I run it. I understand there could be a problem with my Python code, but I've removed unused lines and anything else that could have presented a problem & nothing works.
My code is as follows:
from flask import render_template
from flask import Flask
app = Flask(__name__, template_folder="templates")
@app.route("/")
def mainpage(name):
return render_template("Marianapolis_selfguided.html", name=name)
@app.route("/aboutmepage")
def aboutmepage():
return render_template("aboutme.html")
if __name__ == '__main__':
app.run(debug=True)
In the beginning, I realized that it says they are not accessed in Pylance, so I commented those out. Does anyone know what I can do to access these in Pylance?
Overall, I've tried commenting everything out besides the mainpage & it hasn't worked in a week. I thought maybe about running this in a production server instead of a development server, but I'm not quite sure how to do that.
英文:
I'm trying to make an app & it's my first time using Flask. I've been writing my website in html and running it through the python I set up with Flask. My website was working fine for a month and a half, but now I keep getting an error every time I run it. I understand there could be a problem with my Python code, but I've removed unused lines and anything else that could have presented a problem & nothing works.
My code is as follows:
from flask import render_template
from flask import Flask
#import os
#import sys
#from flask import flash, redirect, url_for
#from werkzeug.utils import secure_filename
#from markupsafe import escape
#from flask_restful import Resource, Api
app = Flask(__name__, template_folder="templates")
@app.route("/")
def mainpage(name):
return render_template("Marianapolis_selfguided.html", name=name)
@app.route("/aboutmepage")
def aboutmepage():
return render_template("aboutme.html")
if __name__ == '__main__':
app.run(debug=True)
In the beginning, I realized that it says they are not accessed in Pylance, so I commented those out. Does anyone know what I can do to access these in Pylance?
Overall, I've tried commenting everything out besides the mainpage & it hasn't worked in a week. I thought maybe about running this in a production server instead of a development server, but I'm not quite sure how to do that.
答案1
得分: 1
错误出在你的路由命名上,应该像这样:
@app.route('/
def main_page(name):
# 你的代码
return ('your_template.html', name=name)
英文:
The error is at your route naming, it should be like so:
@app.route('/<name>')
def main_page(name):
# your code
return ('your_template.html', name=name)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论