Skip to content

Hcha-byte/Flask-Back

Repository files navigation

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

About

A lightweight Flask extension for managing back URLs between pages.

Topics

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Languages