Skip to main content

A lightweight Flask extension for managing back URLs

Project description

logo

codecov Run Tests Python Versions PyPI License

Flask-Back is a lightweight Flask extension for managing "back" URLs to help users return to their previous page in a clean and configurable way.


🚀 Features

  • Automatically or manually save back URLs
  • Use {{ back_url }} in templates
  • Fallback to the referrer if no back URL is saved
  • Exclude specific endpoints from tracking
  • Session-based and lightweight

📦 Installation

pip install flask-back

🧪 Quick Example

from flask import Flask, redirect
from flask_back import Back

app = Flask(__name__)
app.secret_key = "supersecret"

back = Back(app, default_url="/", use_referrer=True)

@app.route("/save")
@back.save_url
def save_page():
    return "This page is now saved as the back URL."

@app.route("/go-back")
def go_back():
    return redirect(back.get_url())

@app.route("/excluded")
@back.exclude
def excluded_page():
    return "This page won't be tracked as a back URL."

In templates:

<a href="{{ back_url }}">Go Back</a>

⚙️ Configuration

You can pass these options when initializing:

Back(app,
     default_url="/fallback",     # Where to go if nothing is saved
     use_referrer=True,           # Use Referer header as fallback
     excluded_endpoints=["static"]  # List of endpoints to skip
)

🧼 API Summary

  • Back(app=None, **settings) – Create the extension
  • save_url(func) – Decorator to manually mark routes as back URLs
  • get_url(default=None) – Retrieve saved URL or fallback
  • clear() – Clear current back URL from session
  • exclude(func) – Decorator to ignore tracking for a route

✅ Testing

pytest
pytest --cov=src --cov-report=term-missing

🤝 Contributing

See CONTRIBUTING.md for setup, testing, and PR tips.


🔐 Security

Found a vulnerability? Please report it via GitHub Issues or email Hcha.Byte@gmail.com.


📦 License

This project is licensed under the MIT License. See LICENSE.


💡 Inspiration

Flask-Back was built to solve a common pattern in web apps: helping users return to the right place—without relying solely on browser behavior. Now you can manage that flow clearly and securely.


⭐ Star the repo if you find it helpful!

GitHub stars

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_back-1.1.2.tar.gz (7.1 kB view details)

Uploaded Source

Built Distribution

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

flask_back-1.1.2-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

Details for the file flask_back-1.1.2.tar.gz.

File metadata

  • Download URL: flask_back-1.1.2.tar.gz
  • Upload date:
  • Size: 7.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.0

File hashes

Hashes for flask_back-1.1.2.tar.gz
Algorithm Hash digest
SHA256 422932ac17d694dce790f68b241372d42f6f821d4a2b4ad86edd06dac9a47e8e
MD5 9027ef43c9a0662356231a55b62b1f35
BLAKE2b-256 83cc2fcbecd5162af6b6f9cf8b223ccedb1f7975a535669a5a4f9aade3fa4b98

See more details on using hashes here.

File details

Details for the file flask_back-1.1.2-py3-none-any.whl.

File metadata

  • Download URL: flask_back-1.1.2-py3-none-any.whl
  • Upload date:
  • Size: 6.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.0

File hashes

Hashes for flask_back-1.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 a4c8c581c02bc60840a2839b91b9a2704bc57c466a0b8b4788ea834927db7ea0
MD5 0f1f5432f10edd7ec1b7f0ecb2186f45
BLAKE2b-256 e23e39d2c89a5cd265993eaf2f0b5d0661305bf07beb4201a67cf59e48626b1d

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