Svelte and Flask (Python)
Reactive framework Svelte easily integrates into Python… In this case, an example of integrating svelte with Flask…
This material is from a series of articles on website development in python: from local development to deployment on a remote server.
How to connect
Inside the file __init__.py directories app we connect the module via Blueprint:
from app.portfolio…routes import portfolio_bp
app.register_blueprint(portfolio_bp, url_prefix=“/ portfolio”)
Now to connect svelte inside the file app / portfolio / routes.py we enter:
# Include main page
# Connecting the main page
@portfolio_bp.route(‘/’)
@login_required
def portfolio_home_route():
return send_from_directory(‘templates / svelte / public / portfolio’, ‘index.html’)
# Path for all static files
# Path to all static files
@portfolio_bp.route(‘/
def portfolio_static_files(path):
return send_from_directory(‘templates / svelte / public / portfolio’, path)
That’s all. Our svelte template will run at domain / portfolio…
The template itself svelte located in the directory app / templates / svelte /… Everything else is standard for svelte.