Whitepaper
Docs
Sign In
Tool
Tool
Website generator
Tool ID
website_generator
Creator
@helvity
Downloads
224+
generates websites
Get
README
No README available
Tool Code
Show
from flask import Flask, request, render_template_string, redirect, url_for app = Flask(__name__) class Tools: dynamic_routes = {} # Dictionary to store dynamic routes and their HTML content @classmethod def add_dynamic_route(cls, route, content): # Ensure the route starts with '/' if not route.startswith('/'): route = '/' + route # Define a new view function that renders the provided HTML content. def dynamic_view(): return render_template_string(content) # Create a unique endpoint name by stripping and replacing slashes. endpoint = route.strip("/").replace("/", "_") or "root" if endpoint in app.view_functions: endpoint += "_dynamic" # Dynamically add the new route to the Flask app. app.add_url_rule(route, endpoint, dynamic_view) cls.dynamic_routes[route] = content @app.route('/') def home(): # Display a form for adding a dynamic route and list all created routes. routes_list = "".join([f"<li><a href='{route}'>{route}</a></li>" for route in Tools.dynamic_routes]) form_html = f""" <h1>Create a Dynamic Route</h1> <form action="/add_route" method="post"> <label for="route">Route Path (e.g. /hello):</label> <input type="text" id="route" name="route" required><br><br> <label for="content">Content (HTML):</label> <textarea id="content" name="content" rows="4" cols="50" required></textarea><br><br> <input type="submit" value="Create Route"> </form> <hr> <h2>Existing Routes</h2> <ul>{routes_list}</ul> """ return form_html @app.route('/add_route', methods=['POST']) def add_route(): # Capture the route and content from the submitted form. route = request.form.get('route').strip() content = request.form.get('content').strip() # Use the Tools class to add the dynamic route. Tools.add_dynamic_route(route, content) return redirect(url_for('home')) if __name__ == '__main__': app.run(debug=True)