Skip to main content

Addon to Flask to edit HTML content in a running app.

Project description

Editable Flask ๐Ÿ“โœจ

Tired of constant client requests to tweak that elusive snippet or image on your /about page? Enter EditableFlask! Simply mark sections of your templates with {% editable %}, and voilร , they're ready for modification in a sleek admin panel. Say goodbye to the hassle of copy adjustments. ๐ŸŽ‰

App Screenshot


๐Ÿš€ Installation

pip install EditableFlask

๐Ÿ› ๏ธ Usage

from flask import Flask
from EditableFlask import Edits

app = Flask(__name__)
edits = Edits(app)

All edits are neatly saved to disk as JSON. Configure your file path to store them alongside your app:

from flask import Flask, render_template
from EditableFlask import Edits
import os

app = Flask(__name__)
app.config['FILE_PATH'] = os.path.dirname(__file__)
edits = Edits(app)

@app.route("/")
def index():
    return render_template('index.html')

๐Ÿ”น Example (Live Editing in Templates)

<!-- index.html -->
<!DOCTYPE html>
<html>
<body>
    <h1>{% editable 'heading' %}My First Heading{% endeditable %}</h1>
    <p>{% editable 'paragraph' %}My first paragraph.{% endeditable %}</p>
</body>
</html>

โœ๏ธ Edits Section

Edit any page with registered editable sections directly in the interface. Currently, only static HTML is supported, with Jinja2 support on the roadmap.

App Screenshot


๐ŸŒŸ Summernote Features

Enable the Summernote HTML Editor for enhanced editing:

app.config['EDITS_SUMMERNOTE'] = True

๐Ÿ–Š Features:

  • Upload Images/Videos ๐Ÿ–ผ๏ธ๐ŸŽฅ
  • Rich Text Formatting ๐ŸŽจ
  • Advanced Editing (Tables, Code Blocks, LaTeX Equations)

For more details, visit SUMMERNOTE's Website.


๐Ÿ”’ Security

๐Ÿš€ Recommended: Flask-Login (Session-Based Lock)

app.config['EDITS_LOCKED'] = True
app.config['EDITS_USERNAME'] = 'your_username'
app.config['EDITS_PASSWORD'] = 'your_password'

๐Ÿ”น Session-Based Locks prevent unauthorized access. ๐Ÿ”น Local Caching for Locking ensures a lightweight security approach.

๐Ÿ›  Recommended: SQLite-Based Lock

app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///users.db'
app.config['EDITS_LOCKED'] = "SQL"

๐Ÿ”น Database-Controlled Edit Locks ๐Ÿ”น Audit Trail for Edits for accountability ๐Ÿ”น Granular Access Control ensures secure editing

๐Ÿ”ง Manual Lock (Custom Auth)

If you already have a user-management system:

@app.before_request
def before_request():
    if request.path.startswith(app.config.get('EDITS_URL')):
        # Custom authentication logic

๐Ÿ”น Flexible Authentication ๐Ÿ”น User-Defined Locking Mechanism


๐Ÿ“Š Additional Features

๐Ÿ“ Analytics Dashboard

Enable it with:

app.config['ENABLE_ANALYTICS'] = True

๐Ÿ”น Tracks Unique IP Visits (15-min timeout) ๐Ÿ”น Displays Visitor Locations on a map ๐Ÿ”น Monitors Server Resource Usage

๐Ÿ’ป Resource Monitoring

Enable it with:

app.config['ENABLE_RESOURCE_MONITOR'] = True

๐Ÿ”น Real-time CPU & RAM Usage ๐Ÿ”น Disk Usage Insights ๐Ÿ”น Graphical Resource Visualization

๐Ÿ“‚ Static File Management

Enable static file editing:

app.config['ENABLE_STATIC'] = True
app.config['EDITABLE_STATIC'] = True

๐Ÿ”น File Uploads & Folder Management ๐Ÿ”น Live Editing for Static Files ๐Ÿ”น Search & Deletion Support


๐Ÿ“‚ Folder Structure

/your_flask_project
โ”‚โ”€โ”€ app.py                # Main Flask app file
โ”‚โ”€โ”€ templates/
โ”‚   โ”œโ”€โ”€ index.html        # Main template file
โ”‚โ”€โ”€ static/               # CSS, JS, images, etc.
โ”‚โ”€โ”€ edits.json            # EditableFlask Edits saved (EditableFlask Managed)
โ”‚โ”€โ”€ intents/              # SQLite database (if used)
โ”‚   โ”œโ”€โ”€ *.db              # Database File (EditableFlask Managed)

For more details, refer to the Flask Documentation.


โš™๏ธ Configuration Options

Customize EditableFlask with various settings to enhance functionality, security, and performance. This guide explains key configurations and their purpose.

๐Ÿ“Œ Application Settings

EditableFlask allows you to customize its name and branding. These settings determine how the app appears in titles and throughout the UI.

app.config['APP_NAME'] = 'EditableFlask'  # Display name for the app (used in <title> tags)
app.config['APP_NAME_HTML'] = 'EditableFlask'  # Name used throughout web pages and UI

๐ŸŒ URL Routing

Define essential URL routes for the application. These settings control access to key pages, such as the admin dashboard and login screen.

app.config['EDITS_URL'] = '/edits'  # URL for the admin dashboard
app.config['LOGIN_ROUTE'] = '/login'  # Login page route

๐Ÿ”’ Session Management

Manage user sessions and authentication timeouts. This setting controls how long a user stays logged in before needing to re-authenticate.

from datetime import timedelta
app.config['PERMANENT_SESSION_LIFETIME'] = timedelta(minutes=60)  # User session timeout duration

๐Ÿ—„๏ธ Database Configuration

Define how the application interacts with the database. These settings determine connection parameters and performance optimizations.

  • SQLALCHEMY_DATABASE_URI
    Specifies the database connection string. By default, it uses SQLite with a file named users.db, but it can be customized for PostgreSQL, MySQL, etc.

    app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///users.db'
    
  • SQLALCHEMY_TRACK_MODIFICATIONS
    Controls whether SQLAlchemy tracks object modifications and emits signals. Keeping this disabled improves performance unless event tracking is needed.

    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
    

Resources ๐Ÿ“š

๐Ÿ”น MDI Icons From pictogrammers ๐Ÿ”น Flask ๐Ÿ”น Jinja ๐Ÿ”น Flask-Login ๐Ÿ”น Flask-SQLAlchemy ๐Ÿ”น SQLAlchemy ๐Ÿ”น psutil ๐Ÿ”น platform ๐Ÿ”น socket ๐Ÿ”น subprocess ๐Ÿ”น datetime ๐Ÿ”น HTML CSS JS ๐Ÿ”น Bootstrap ๐Ÿ”น jQuery.ajax ๐Ÿ”น OpenStreetMap ๐Ÿ”น Chart.js

Authors โœ๏ธ

View This Repository on GitHub: EditableFlask

Support ๐Ÿ’ฌ

For support, email info@mahirshah.dev or contact me through my Website.

Logo

License ๐Ÿ“œ

MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the โ€œSoftwareโ€), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED โ€œAS ISโ€, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGE

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

editableflask-2.0.0.1.tar.gz (392.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

editableflask-2.0.0.1-py3-none-any.whl (403.0 kB view details)

Uploaded Python 3

File details

Details for the file editableflask-2.0.0.1.tar.gz.

File metadata

  • Download URL: editableflask-2.0.0.1.tar.gz
  • Upload date:
  • Size: 392.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.0

File hashes

Hashes for editableflask-2.0.0.1.tar.gz
Algorithm Hash digest
SHA256 9e1d2aad3f03ae6a59b8bc76c6bd8c4698f518c1bf2cd42b4c312b0ead26e560
MD5 78b3f46fc2016fdb25462438a020f1d0
BLAKE2b-256 a8948634415a79d6ee2655ca3c1f1747b8527a7c6d22fb3bd60f8103db0a5cf9

See more details on using hashes here.

File details

Details for the file editableflask-2.0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for editableflask-2.0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 01ab69d513bab6c7237033d973888931bbcc96a77a667b15e7d2910174949e57
MD5 097458ef41646b70f0e2d2dd6ac7bb90
BLAKE2b-256 0bb0dc3022a830ebf4e00db917efefd2f926a7d7187e15cfa5e3e5a776302c25

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page