Server search

Taminator

Neues Mitglied
I need for a school project an Server where I can have an Python backend for my Website(html, JavaScript, CSS). Does anybody know a Server for that purpose?
 
You can use Flask for your purpose. Install it with pip install -U Flask.

The following skeleton can be used as template to host the website from a local storage:

Python:
import os
import shutil
import random
from flask import Flask, request, jsonify, send_from_directory, make_response
from werkzeug.exceptions import BadRequest

app = Flask(__name__)
app.config["APP_WEB_STATIC_PATH"] = os.path.normpath(os.getcwd())


@app.errorhandler(Exception)
def handle_generic_exception(e: Exception):
    return str(e), 500


@app.errorhandler(BadRequest)
def handle_generic_exception(e: BadRequest):
    return str(e), 400


@app.route("/api/v1/hello")
def rename():
    itemx = ["Hello", "World"]
    return jsonify(itemx)


@app.route("/submit", methods=["POST"])
def upload():
    return make_response(str(request.form) + "\r\nOK")


@app.route("/", defaults={"path": "index.html"})
@app.route("/<path:path>")
def default(path):
    return send_from_directory(app.config["APP_WEB_STATIC_PATH"], path)


if __name__ == "__main__":
    app.run(debug=True)
 
Zurück
Oben Unten