Skip to main content

A python package to create flask project with svelte frontend.

Project description

Flask-Svelte Documentation

Welcome to Flask-Svelte, a python package that integrates Svelte with Flask. This integration brings together the best of both worlds: Svelte's reactive frontend capabilities and Flask's robust backend, providing a seamless experience for web application development.

Note: This package is still in development. The API is subject to change.

Key Features

  • Svelte Integration with Flask: Effortlessly serve Svelte templates as dynamic components within Flask applications.
  • Automatic Live Reloading: Implement livereload for instant browser updates when templates are modified.
  • Simplified Project Management: Utilize the CLI for effortless project setup and template handling.
  • Use Python data in Svelte: The render_template function extends Flask's capability, allowing direct data integration into Svelte templates for dynamic content rendering.
  • Tailwind CSS Preinstalled: Comes with Tailwind CSS, a utility-first CSS framework for rapid UI development, preconfigured and ready to use.

Getting Started

Installation and Project Setup

  1. Prerequisites: Install Node.js and Python.
  2. Install Flask-Svelte:
    pip install flask-svelte
    
  3. Create a New Project:
    flask-svelte create <project_name>
    
  4. Navigate to the Project Directory:
    cd <project_name>
    
  5. Install JavaScript Dependencies:
    npm install
    

Development Workflow

  • Start Development Server:
    npm run dev
    
  • Add New Svelte Templates:
    flask-svelte add-page <template_name>
    
    Generates Svelte files in svelte/<template_name>. Edit them and see the changes in the browser. Note: The npm run dev command must be restarted for new templates to be recognized.

Important Usage Notes

  1. Production Build: Use npm run build for deployment readiness. Post-build, the svelte directory is optional.
  2. Data Integration in Templates: Replace flask.render_template with flask_svelte.render_template for enhanced data passing. Example:
    from flask_svelte import render_template
    from app import app
    
    @app.route('/')
    def index():
        return render_template('index.html', name='World')
    
  3. Accessing Data in Svelte: Retrieve Flask-passed data in Svelte with {{ app.data["key"] }}. Example:
    <h1>Hello {{ app.data["name"] }}!</h1>
    

Enhanced Documentation

render_template Function

  • Purpose: Replaces Flask's render_template for integrating Python and JavaScript.
  • Usage: Passes variables and data from Flask to Svelte components for interactive web applications.

app.data Object

  • Functionality: Facilitates data transfer between Flask and Svelte.
  • Access in Svelte: Retrieve Flask data in Svelte templates via {{ app.data["key"] }}.

Command-Line Interface (CLI) Commands

  • Create a New Project:

    flask-svelte create <project_name>
    

    Sets up a new Flask-Svelte project environment.

  • Add a New Template:

    flask-svelte add-page <template_name>
    

    Adds a new Svelte template to your project, creating necessary files in svelte/<template_name>.

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

flask_svelte-1.0.1.tar.gz (7.4 kB view details)

Uploaded Source

Built Distribution

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

flask_svelte-1.0.1-py3-none-any.whl (10.3 kB view details)

Uploaded Python 3

File details

Details for the file flask_svelte-1.0.1.tar.gz.

File metadata

  • Download URL: flask_svelte-1.0.1.tar.gz
  • Upload date:
  • Size: 7.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.10.5 Windows/10

File hashes

Hashes for flask_svelte-1.0.1.tar.gz
Algorithm Hash digest
SHA256 f27859aac0da05bf9f39d7860fd65a18b5ba338873d571d2110c323e2d6e43b4
MD5 f52f3083ef451fb1fa888a8ba797e445
BLAKE2b-256 4460d252cd79f9a35fb86465ea91d4ecd087e0b37303b61de132c4fb033f4a42

See more details on using hashes here.

File details

Details for the file flask_svelte-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: flask_svelte-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 10.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.10.5 Windows/10

File hashes

Hashes for flask_svelte-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 85a3b42f36108e2a2939e0509aca3719d2d6999ce21e73fdbdfdecdf85c35f80
MD5 4b1dfb8143f12a4798ae9fc5c1cddd07
BLAKE2b-256 9d3527bdd19fd0620428376c1be07cd3cb83adb0821a3574508ba60fc4b44dd8

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