在Flask中,为什么我的代码以前正常运行,现在却出现了内部服务器错误?

huangapple go评论65阅读模式
英文:

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)

huangapple
  • 本文由 发表于 2023年4月13日 23:45:02
  • 转载请务必保留本文链接:https://go.coder-hub.com/76007388.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定