Internal Server Error

The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.

这是app.py的代码,这个运行用的端口号是5500

from flask import Flask, render_template

from livereload import Server

app = Flask(__name__)

@app.route("/")

def index():

return render_template("index.html", title="

welcome to flask

", body="
hello flask
")

@app.template_filter("md")

def markdown_to_html(txt):

from markdown import markdown

return markdown(txt)

def read_md(filename):

with open(filename) as md_file:

content = reduce(lambda x, y: x+y, md_file.readlines())

return content.decode("utf-8")

@app.context_processor

def inject_method():

return dict(read_md=read_md)

if __name__ == "__main__":

live_server = Server(app.wsgi_app)

live_server.watch("**/*.*")

live_server.serve(open_url=True)

设置app.py debug的提示

下面这个是flaskblog.py的代码,运行端口号是5000,

from flask import Flask, render_template, request, redirect, url_for, make_response

from werkzeug.routing import BaseConverter

from werkzeug.utils import secure_filename

from flask.ext.script import Manager

from os import path

class RegexConverter(BaseConverter):

def __init__(self, url_map, *items):

super(RegexConverter, self).__init__(url_map)

self.regex = items[0]

app = Flask(__name__)

app.url_map.converters["regex"] = RegexConverter

manager = Manager(app)

@app.route('/')

def hello_world():

response = make_response(render_template("index.html", content="welcome to flask web development"))

response.set_cookie("username","")

return response

@app.route('/service')

def service():

return 'service'

@app.route('/about')

def about():

return 'about'

@app.route("/user/")

def user(user_id):

return "user is %s" % user_id

@app.route("/login",methods=['GET','POST'])

def login():

if request.method == "post":

username = request.form["username"]

password = request.form["password"]

else:

username = request.args["username"]

return render_template("login.html", method=request.method)

@app.route("/upload",methods=["GET","POST"])

def upload():

if request.method == "post":

f = request.files("file")

basepath = path.abspath(path.dirname(__file__))

upload_path = path.join(basepath, "static/upload")

f.save(upload_path, secure_filename(f.filename))

return redirect(url_for("upload"))

return render_template("upload.html")

@app.errorhandler(404)

def page_note_found(error):

return render_template("404.html")

@manager.command

def dev():

from livereload import Server

live_server = Server(app.wsgi_app)

live_server.watch("*", "*.*")

live_server.serve(open_url=True)

if __name__ == '__main__':

manager.run()

#app.run()

debug提示如下:

Logo

技术共进,成长同行——讯飞AI开发者社区

更多推荐