I need a solution for creating completely random HTML/CSS templates, but visually…
- User
I need a solution for creating completely random HTML/CSS templates, but visually appealing. Potentially tailwind is a good option, as it also gives us the option of using custom prefixes. We need to make sure the class names are unique for each generation. Templates should have different layouts such as full width, contained, left sidebar, right sidebar etc.
Whatever we make this PoC in, it needs to work in the browser and every pageview should be a new template.
it cannot be JavaScript as that would be obvious what is happening. Either Python or PHP seem like good choices.
- Assistant
Here's a Python-based solution using Flask that generates random, visually appealing HTML/CSS templates on each page load:
Core Structure
# app.py from flask import Flask, render_template_string import random import string import hashlib from datetime import datetime app = Flask(__name__) class RandomTemplateGenerator: def __init__(self): self.layouts = ['full-width', 'contained', 'left-sidebar', 'right-sidebar', 'grid-2col', 'grid-3col'] self.color_schemes = [ {'primary': '#3B82F6', 'secondary': '#EF4444', 'accent': '#10B981', 'bg': '#F8FAFC', 'text': '#1F2937'}, {'primary': '#8B5CF6', 'secondary': '#F59E0B', 'accent': '#EF4444', 'bg': '#FEFEFE', 'text': '#374151'}, {'primary': '#059669', 'secondary': '#DC2626', 'accent': '#7C3AED', 'bg': '#F9FAFB', 'text': '#111827'}, {'primary': '#DC2626', 'secondary': '#2563EB', 'accent': '#059669', 'bg': '#FFFBEB', 'text': '#1F2937'}, ] def generate_unique_prefix(self): """Generate unique class prefix based on timestamp and random string""" timestamp = str(int(datetime.now().timestamp())) random_str = ''.join(random.choices(string.ascii_lowercase, k=6)) return f"tpl_{hashlib.md5((timestamp + random_str).encode()).hexdigest()[:8]}" def get_random_layout(self): return random.choice(self.layouts) def get_random_colors(self): return random.choice(self.color_schemes) def generate_content_blocks(self, prefix): """Generate random content sections""" blocks = [] num_blocks = random.randint(3, 6) block_types = ['hero', 'features', 'testimonial', 'cta', 'gallery', 'text'] for i in range(num_blocks): block_type = random.choice(block_types) blocks.append({ 'type': block_type, 'class': f"{prefix}_block_{i}", 'content': self.get_block_content(block_type) }) return blocks def get_block_content(self, block_type): content_map = { 'hero': { 'title': random.choice(['Welcome to Innovation', 'Transform Your Business', 'Discover Excellence', 'Build Something Amazing']), 'subtitle': random.choice(['Leading the way in digital transformation', 'Your success is our mission', 'Crafting exceptional experiences', 'Where creativity meets technology']) }, 'features': { 'title': 'Our Features', 'items': random.sample(['Fast Performance', 'Secure Platform', 'Easy Integration', '24/7 Support', 'Scalable Solution', 'Modern Design'], 3) }, 'testimonial': { 'quote': random.choice([ 'This platform transformed our business completely.', 'Outstanding service and incredible results.', 'The best investment we\'ve made for our company.' ]), 'author': random.choice(['Sarah Johnson', 'Mike Chen', 'Emily Rodriguez', 'David Kim']) }, 'cta': { 'title': random.choice(['Ready to Get Started?', 'Join Thousands of Users', 'Start Your Journey Today']), 'button': random.choice(['Get Started Now', 'Learn More', 'Try It Free', 'Contact Us']) } } return content_map.get(block_type, {'title': 'Content Block'}) generator = RandomTemplateGenerator() @app.route('/') def index(): # Generate unique template for each request prefix = generator.generate_unique_prefix() layout = generator.get_random_layout() colors = generator.get_random_colors() blocks = generator.generate_content_blocks(prefix) # Generate CSS css = generate_css(prefix, layout, colors) # Generate HTML html = generate_html(prefix, layout, blocks) template = f""" <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Random Template - {layout.title()}</title> <style>{css}</style> </head> <body class="{prefix}_body"> {html} </body> </html> """ return render_template_string(template) def generate_css(prefix, layout, colors): base_css = f""" .{prefix}_body {{ margin: 0; padding: 0; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; background-color: {colors['bg']}; color: {colors['text']}; line-height: 1.6; }} .{prefix}_container {{ max-width: 1200px; margin: 0 auto; padding: 0 20px; }} .{prefix}_header {{ background: linear-gradient(135deg, {colors['primary']}, {colors['secondary']}); color: white; padding: 2rem 0; text-align: center; }} .{prefix}_nav {{ background: rgba(255,255,255,0.1); padding: 1rem 0; margin-top: 1rem; }} .{prefix}_nav ul {{ list-style: none; display: flex; justify-content: center; gap: 2rem; margin: 0; padding: 0; }} .{prefix}_nav a {{ color: white; text-decoration: none; font-weight: 500; transition: opacity 0.3s; }} .{prefix}_nav a:hover {{ opacity: 0.8; }} .{prefix}_main {{ padding: 3rem 0; }} .{prefix}_block {{ margin-bottom: 4rem; padding: 2rem; background: white; border-radius: 12px; box-shadow: 0 4px 6px rgba(0,0,0,0.1); }} .{prefix}_hero {{ background: linear-gradient(45deg, {colors['primary']}, {colors['accent']}); color: white; text-align: center; padding: 4rem 2rem; }} .{prefix}_hero h1 {{ font-size: 3rem; margin-bottom: 1rem; font-weight: 700; }} .{prefix}_hero p {{ font-size: 1.25rem; opacity: 0.9; }} .{prefix}_features {{ display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 2rem; padding: 2rem 0; }} .{prefix}_feature {{ text-align: center; padding: 2rem; background: {colors['bg']}; border-radius: 8px; border: 2px solid {colors['primary']}; }} .{prefix}_btn {{ background: {colors['primary']}; color: white; padding: 12px 24px; border: none; border-radius: 6px; font-size: 1rem; font-weight: 600; cursor: pointer; transition: all 0.3s; text-decoration: none; display: inline-block; }} .{prefix}_btn:hover {{ background: {colors['secondary']}; transform: translateY(-2px); }} .{prefix}_footer {{ background: {colors['text']}; color: white; text-align: center; padding: 2rem 0; margin-top: 4rem; }} """ # Layout-specific CSS layout_css = get_layout_css(prefix, layout, colors) return base_css + layout_css def get_layout_css(prefix, layout, colors): layout_styles = { 'full-width': f""" .{prefix}_layout {{ width: 100%; }} """, 'contained': f""" .{prefix}_layout {{ max-width: 1200px; margin: 0 auto; }} """, 'left-sidebar': f""" .{prefix}_layout {{ display: grid; grid-template-columns: 300px 1fr; gap: 2rem; max-width: 1200px; margin: 0 auto; }} .{prefix}_sidebar {{ background: {colors['primary']}; color: white; padding: 2rem; border-radius: 8px; height: fit-content; }} """, 'right-sidebar': f""" .{prefix}_layout {{ display: grid; grid-template-columns: 1fr 300px; gap: 2rem; max-width: 1200px; margin: 0 auto; }} .{prefix}_sidebar {{ background: {colors['primary']}; color: white; padding: 2rem; border-radius: 8px; height: fit-content; }} """, 'grid-2col': f""" .{prefix}_layout {{ display: grid; grid-template-columns: 1fr 1fr; gap: 2rem; max-width: 1200px; margin: 0 auto; }} """, 'grid-3col': f""" .{prefix}_layout {{ display: grid; grid-template-columns: repeat(3, 1fr); gap: 2rem; max-width: 1200px; margin: 0 auto; }} """ } return layout_styles.get(layout, '') def generate_html(prefix, layout, blocks): header_html = f""" <header class="{prefix}_header"> <div class="{prefix}_container"> <h1>Dynamic Template</h1> <nav class="{prefix}_nav"> <ul> <li><a href="#home">Home</a></li> <li><a href="#about">About</a></li> <li><a href="#services">Services</a></li> <li><a href="#contact">Contact</a></li> </ul> </nav> </div> </header> """ # Generate main content based on layout if layout in ['left-sidebar', 'right-sidebar']: sidebar_html = f""" <aside class="{prefix}_sidebar"> <h3>Navigation</h3> <ul style="list-style: none; padding: 0;"> <li style="margin-bottom: 1rem;"><a href="#" style="color: white;">Dashboard</a></li> <li style="margin-bottom: 1rem;"><a href="#" style="color: white;">Analytics</a></li> <li style="margin-bottom: 1rem;"><a href="#" style="color: white;">Settings</a></li> <li style="margin-bottom: 1rem;"><a href="#" style="color: white;">Help</a></li> </ul> </aside> """ content_html = generate_blocks_html(prefix, blocks) if layout == 'left-sidebar': main_html = f""" <main class="{prefix}_main"> <div class="{prefix}_layout"> {sidebar_html} <div>{content_html}</div> </div> </main> """ else: # right-sidebar main_html = f""" <main class="{prefix}_main"> <div class="{prefix}_layout"> <div>{content_html}</div> {sidebar_html} </div> </main> """ else: content_html = generate_blocks_html(prefix, blocks) main_html = f""" <main class="{prefix}_main"> <div class="{prefix}_layout"> {content_html} </div> </main> """ footer_html = f""" <footer class="{prefix}_footer"> <div class="{prefix}_container"> <p>© 2024 Dynamic Template. Layout: {layout.title()}</p> </div> </footer> """ return header_html + main_html + footer_html def generate_blocks_html(prefix, blocks): html = "" for block in blocks: if block['type'] == 'hero': html += f""" <section class="{prefix}_block {prefix}_hero"> <h1>{block['content']['title']}</h1> <p>{block['content']['subtitle']}</p> <a href="#" class="{prefix}_btn">Get Started</a> </section> """ elif block['type'] == 'features': features_html = "" for feature in block['content']['items']: features_html += f""" <div class="{prefix}_feature"> <h3>{feature}</h3> <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p> </div> """ html += f""" <section class="{prefix}_block"> <h2 style="text-align: center; margin-bottom: 2rem;">{block['content']['title']}</h2> <div class="{prefix}_features"> {features_html} </div> </section> """ elif block['type'] == 'testimonial': html += f""" <section class="{prefix}_block" style="text-align: center; font-style: italic;"> <blockquote style="font-size: 1.5rem; margin-bottom: 1rem;"> "{block['content']['quote']}" </blockquote> <cite style="font-weight: 600;">— {block['content']['author']}</cite> </section> """ elif block['type'] == 'cta': html += f""" <section class="{prefix}_block" style="text-align: center;"> <h2>{block['content']['title']}</h2> <p style="margin-bottom: 2rem;">Join thousands of satisfied customers today.</p> <a href="#" class="{prefix}_btn">{block['content']['button']}</a> </section> """ return html if __name__ == '__main__': app.run(debug=True, port=5000)Key Features
Unique Class Generation: Each page load creates a unique prefix using timestamp + random string + MD5 hash, ensuring no class name conflicts.
Multiple Layouts: Supports full-width, contained, left sidebar, right sidebar, 2-column grid, and 3-column grid layouts.
Random Color Schemes: Multiple predefined color palettes that are randomly selected.
Dynamic Content: Generates different content blocks (hero, features
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.