Skip to main content

Blended python flask is a web framework, it is a python module that lets you develop web applications easily. Flask is very Pythonic. It is easy to get started with Flask, because it does not have a huge learning curve. On top of that it is very explicit, which increases readability. Simply, you can install the blended python flask, specify the path of your theme, run the server and can browse your website which is running on a Blended theme.

Installation

pip install blendedux

Usages

Setup of Blended Python Flask

Run the following commands sequentially. First will create virtual environment, second will take you to the newly created virtual environment, third will activate the virtual environment and fourth will install blendedux inside the virtual environment.

python -m virtualenv env_name
cd env_name
Scripts\activate
pip install blendedux

Create a file name app.py in the root directory and paste below line of code and save.

from flask import Flask
from blendedUx import *
from blendedUx.blended_flask.bl_flask_app import Bl_Flask

PACKAGE_DIR = "themes-directory"

app = Bl_Flask(__name__, package_dir= PACKAGE_DIR)

user_name = 'user_name'
theme_name = 'theme_name'
password = ''

theme = app.load(theme_name, user_name)

@app.route("/css/<path:path>")
@get_css('css_path')
def css():
   pass
@app.route("/media/<path:path>")
@get_media('media_path')
def media():
    pass
@app.route("/js/<path:path>")
@get_js('js_path')
def js():
    pass

@app.route('/')
def home(**kwargs):
    """
    """
    context = theme
    file_content = get_template('home.html')
    try:
        return render_code(file_content, context)
    except UnicodeDecodeError:
        return render_code(file_content.decode('utf-8'), context)

if __name__ == "__main__":
    app.run()

Note: Please specify your path in the package directory. You can point to your working directory which you have set up during cli and make sure that blended directory structures is there and it has a valid blended theme. Password is optional. For an example:

PACKAGE_DIR = "C:/Users/themes" 
user_name = 'blended' 
theme_name = 'base_theme' 
password = '' 

How to Include the theme into your flask application?

Create a templates directory in the root and create a home.html inside the templates directory and paste below line of code in the home.html and save.

{% extends theme.template.home|template %} 
{% block title %}
<title>My Blended Site </title> 
{% endblock title %} 
{% block css %}
<link rel="stylesheet" href="{{css(theme)}}">
{% endblock %}

Note: It is extending the home template of the theme. Extending a predefined Blended template should allow you to add a new page in your flask application. This host template is extending the theme base template named as home.html. Base templates are part of Blended theme which resides in the html directory.For an example:

{% extends theme.template.home|template %}

Run the Flask Server

python app.py

Just load the below URL (http://localhost:5000/) in a browser to see the output.

API

CSS ENDPOINT

By default, the /static directory will serve the static contents. If you want to provide the path of CSS then you can change this by following API:

  @app.route("/css/<path:path>")
  @get_css("css_path") 
  def css(): 
    pass

Note: User will need to give the absolute path in the css_path like this @get_css("C:/blendedUx/static/css")

Js ENDPOINT

By default, the /static directory will serve the static contents. If you want to provide the path of js then you can change this by following API:

  @app.route("/js/<path:path>")
  @get_js("js_path") 
  def js(): 
    pass

Note: User will need to give the absolute path in the js_path like this @get_js("C:/blendedUx/static/js")

Media ENDPOINT

Add Media Endpoint By default application will host the media at /static directory in the root but you can change this by following API:

  @app.route("/media/<path:path>")
  @get_media("media_path") 
  def media(): 
     pass

Note: User will need to give the absolute path in the media_path like this @get_media("C:/blendedUx/static/media")

Add Route

  @app.route("/")
  def home(**kwargs):
    """
    """
    context = theme 
    file_content = get_template("home.html")
    try:
      return render_code(file_content, context)
    except UnicodeDecodeError:
      return render_code(file_content.decode("utf-8"), context)

Note: It is registering the root URL for your application. This route is rendering a home.html template file by accepting the Blended theme context object. The home.html is a Blended host template and you can add many more as per your requirements in templates directory and then define a route for that template based on above code snippet in app.py.

For more details go to Quickstart Python Flask

License

MIT

Release files for blendedux 0.1.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for blendedux 0.1.4
File Size Uploaded
blendedux-0.1.4.tar.gz 245.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for blendedux 0.1.4
File Interpreter ABI Platform
blendedux-0.1.4-py3-none-any.whl Python 3 none any Details

Total release size: 790.7 kB

Release files / blendedux-0.1.4.tar.gz

Download URL blendedux-0.1.4.tar.gz
Size 245.2 kB
Tags Source
SHA-256 checksum
How to use checksums
e42768dde69c76c790d520526bbf1fe400d9a9a65262d4db243c31a93cbaa62c
BLAKE2b-256 checksum
How to use checksums
f51b3ba85c8e13e14b0c97868987d177d635e17c2678596ffaf173069298ed29
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.3

Release files / blendedux-0.1.4-py3-none-any.whl

Download URL blendedux-0.1.4-py3-none-any.whl
Size 545.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8372e5767d88a440dfebaf2c6c416427d9d1b1af66ad06164a199ffa0e1fff1c
BLAKE2b-256 checksum
How to use checksums
000bfea06fbafeaef9cea8f261aad990031916323f3a7fed226fa3e83e975ee9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.3

Release history Release notifications | RSS feed

This release

0.1.4 This release

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

0.0.2

2 release files

0.0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page