Spaces:
Sleeping
Sleeping
feat: enhance functionality with templates, fix jinja2/vue conflicts, and improve error handling
f2970fe | from flask import Flask, render_template, request, send_file, make_response | |
| import io | |
| import json | |
| import os | |
| import traceback | |
| app = Flask(__name__) | |
| def health(): | |
| return "OK", 200 | |
| def handle_exception(e): | |
| traceback.print_exc() | |
| return f"Internal Server Error: {str(e)}", 500 | |
| def index(): | |
| return render_template('builder.html') | |
| 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) | |