तो यह शर्मनाक है। मुझे एक आवेदन मिला है जिसे मैंने एक साथ फेंक दिया है Flaskऔर अभी के लिए यह सीएसएस और जेएस के कुछ लिंक के साथ एक ही स्थिर HTML पृष्ठ पर काम कर रहा है। और मुझे पता नहीं चल पाया कि डॉक्यूमेंटेशन में Flaskस्टैटिक फाइल्स को वापस करने का वर्णन है। हां, मैं उपयोग कर सकता हूं render_templateलेकिन मुझे पता है कि डेटा को गति नहीं दी गई है। मैंने सोचा था send_fileया url_forसही बात थी, लेकिन मैं उन लोगों को काम करने के लिए नहीं मिला। इस बीच, मैं फाइलें खोल रहा हूं, सामग्री पढ़ रहा हूं, और Responseउपयुक्त mimetype के साथ हेराफेरी कर रहा हूं :
import os.path
from flask import Flask, Response
app = Flask(__name__)
app.config.from_object(__name__)
def root_dir(): # pragma: no cover
return os.path.abspath(os.path.dirname(__file__))
def get_file(filename): # pragma: no cover
try:
src = os.path.join(root_dir(), filename)
# Figure out how flask returns static files
# Tried:
# - render_template
# - send_file
# This should not be so non-obvious
return open(src).read()
except IOError as exc:
return str(exc)
@app.route('/', methods=['GET'])
def metrics(): # pragma: no cover
content = get_file('jenkins_analytics.html')
return Response(content, mimetype="text/html")
@app.route('/', defaults={'path': ''})
@app.route('/<path:path>')
def get_resource(path): # pragma: no cover
mimetypes = {
".css": "text/css",
".html": "text/html",
".js": "application/javascript",
}
complete_path = os.path.join(root_dir(), path)
ext = os.path.splitext(path)[1]
mimetype = mimetypes.get(ext, "text/html")
content = get_file(complete_path)
return Response(content, mimetype=mimetype)
if __name__ == '__main__': # pragma: no cover
app.run(port=80)
कोई इसके लिए एक कोड नमूना या url देना चाहता है? मुझे पता है कि यह मृत सरल होने जा रहा है।

