Skip to main content

PJAX Templating for Flask Applications

Project description

Flask-PJAX

https://travis-ci.org/rhyselsmore/flask-pjax.png?branch=master https://pypip.in/d/Flask-PJAX/badge.png

Add a fairly basic handler for PJAX to Flask.

Allows you to specify a base template for both a normal request or a PJAX request. This allows you to return the required code blocks, and choose what you wish to render.

Installation

pip install flask-pjax

Configuration

Configiguring Flask-PJAX is fairly simple. To get started, initalise it against your application.

from flask import Flask
from flask_pjax import PJAX

app = Flask(__name__)
PJAX(app)

or

from flask import Flask
from flask_pjax import PJAX

app = Flask(__name__)
pjax = PJAX(app)

or

from flask import Flask
from flask_pjax import PJAX

pjax = PJAX()

def create_app():
    app = Flask(__name__)
    pjax.init_app(app)
    return app

Currently, the base template for your PJAX request is the only configuration item. This is set to the location of the template within your project.

PJAX_BASE_TEMPLATE = "pjax.html"

Usage

You can return your templates like you normally do.

# app.py

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

Your base template remains the same.

# base.html

<html>
<head>
    <title>Woop</title>
</head>
<body>
    {% block content %}{% endblock %}
</body>
</html>

And you create a PJAX base template.

# pjax.html

<title>Woop</title>

{% block content %}{% endblock %}

And within your index template, you can specify your base template:

# index.html

{% extends pjax('base.html') %}

<title>Woop - Home</title>

{% block content %}
This is my homepage
{% endblock %}

This will render the pjax.html for PJAX requests, and the base for non-PJAX requests.

Furthermore, you can specify a custom PJAX Base Template:

{% extends pjax('base.html', pjax='/base/custom_pjax_template') %}

Contribute

  1. Check for open issues or open a fresh issue to start a discussion around a feature idea or a bug. There is a Contributor Friendly tag for issues that should be ideal for people who are not very familiar with the codebase yet.

  2. Fork the repository on Github to start making your changes to the master branch (or branch off of it).

  3. Write a test which shows that the bug was fixed or that the feature works as expected.

  4. Send a pull request and bug the maintainer until it gets merged and published.

History

0.0.1 (29/9/2013)

  • Conception.

  • Initial Commit of Package to GitHub.

  • First Release.

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-PJAX-0.0.1.tar.gz (3.6 kB view details)

Uploaded Source

File details

Details for the file Flask-PJAX-0.0.1.tar.gz.

File metadata

  • Download URL: Flask-PJAX-0.0.1.tar.gz
  • Upload date:
  • Size: 3.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for Flask-PJAX-0.0.1.tar.gz
Algorithm Hash digest
SHA256 c531efa52a43fecbc34debaadca67b7d9147a7a86910af7d086d5f377b080753
MD5 03765036076e6098f16f22d067a22ca3
BLAKE2b-256 c08a5f010c2016dadd2f8a2db987702b3f70b75f42bb3abeebbb56327a4aefd7

See more details on using hashes here.

Supported by

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