duqing2026's picture
feat: enhance functionality with templates, fix jinja2/vue conflicts, and improve error handling
f2970fe
Raw
History Blame Contribute Delete
1.18 kB
from flask import Flask, render_template, request, send_file, make_response
import io
import json
import os
import traceback
app = Flask(__name__)
@app.route('/health')
def health():
return "OK", 200
@app.errorhandler(Exception)
def handle_exception(e):
traceback.print_exc()
return f"Internal Server Error: {str(e)}", 500
@app.route('/')
def index():
return render_template('builder.html')
@app.route('/export', methods=['POST'])
def export():
data = request.json
# Generate the standalone HTML
# We pass the JSON data to the template, which will be embedded into the JS
html_content = render_template('export_template.html',
initial_data=json.dumps(data),
page_title=data.get('title', 'Checklist'))
# Create a file-like object
mem = io.BytesIO()
mem.write(html_content.encode('utf-8'))
mem.seek(0)
return send_file(
mem,
as_attachment=True,
download_name=f"{data.get('title', 'checklist')}.html",
mimetype='text/html'
)
if __name__ == '__main__':
app.run(host='0.0.0.0', port=7860, debug=True)