import os from datetime import datetime from flask import Flask, render_template, request, redirect, url_for, flash, jsonify from slugify import slugify from config import config from models import db, User, BlogPost, ForumCategory, ForumTopic, ForumReply, ContactMessage def create_app(config_name=None): if config_name is None: config_name = os.environ.get('FLASK_CONFIG', 'default') app = Flask(__name__) app.config.from_object(config[config_name]) db.init_app(app) with app.app_context(): db.create_all() seed_data() # Context processor for templates @app.context_processor def inject_now(): return {'now': datetime.utcnow()} # ==================== Company Pages ==================== @app.route('/') def index(): latest_posts = BlogPost.query.filter_by(published=True)\ .order_by(BlogPost.created_at.desc())\ .limit(3).all() return render_template('index.html', latest_posts=latest_posts) @app.route('/about') def about(): return render_template('about.html') @app.route('/services') def services(): return render_template('services.html') @app.route('/contact') def contact(): return render_template('contact.html') @app.route('/contact/submit', methods=['POST']) def contact_submit(): name = request.form.get('name') email = request.form.get('email') subject = request.form.get('subject') message = request.form.get('message') if not all([name, email, subject, message]): return '
Flask and HTMX make a powerful combination for building interactive web applications without the complexity of a JavaScript framework.
HTMX allows you to access modern browser features directly from HTML, making it easy to build dynamic user interfaces with minimal JavaScript.
First, create a new Flask project and install the required dependencies. Then, add HTMX to your templates and start building interactive features.
''', 'published': True }, { 'title': 'Building Scalable APIs with Python', 'slug': 'building-scalable-apis-python', 'excerpt': 'Best practices for designing and building scalable REST APIs using Python.', 'content': '''Building scalable APIs requires careful planning and adherence to best practices.
Follow REST principles, use proper HTTP methods, and design your endpoints to be intuitive and consistent.
Implement caching, pagination, and rate limiting to ensure your API can handle high traffic.
''', 'published': True }, { 'title': 'The Future of Web Development', 'slug': 'future-web-development', 'excerpt': 'Exploring emerging trends and technologies shaping the future of web development.', 'content': '''The web development landscape is constantly evolving. Let's explore what's next.
From WebAssembly to edge computing, new technologies are changing how we build web applications.
Staying current with these trends will help you build better applications and advance your career.
''', 'published': True } ] for post_data in posts: post = BlogPost(author_id=1, **post_data) db.session.add(post) # Create forum categories categories = [ {'name': 'General Discussion', 'slug': 'general', 'description': 'General topics and discussions about software development.', 'order': 1}, {'name': 'Help & Support', 'slug': 'help', 'description': 'Get help with technical problems and questions.', 'order': 2}, {'name': 'Showcase', 'slug': 'showcase', 'description': 'Share your projects and get feedback from the community.', 'order': 3}, {'name': 'Off Topic', 'slug': 'off-topic', 'description': 'Everything else that doesn\'t fit elsewhere.', 'order': 4} ] for cat_data in categories: category = ForumCategory(**cat_data) db.session.add(category) db.session.commit() # Create sample forum topics general = ForumCategory.query.filter_by(slug='general').first() if general: topic = ForumTopic( title='Welcome to the DirectLX Community!', content='Welcome everyone! This is a place to discuss software development, share knowledge, and connect with other developers. Feel free to introduce yourself!', category_id=general.id, author_id=1, is_pinned=True ) db.session.add(topic) db.session.commit() # Create the application instance app = create_app() if __name__ == '__main__': app.run(debug=True, port=5000)