1
0
Fork
You've already forked django-contextactions
1
Simply add context related links to your Django views.
  • Python 98.2%
  • HTML 1.8%
2026年06月22日 09:35:37 +02:00
project register contextactions.tests.urls in urlpatterns 2026年06月19日 22:17:04 +02:00
src/contextactions import: filter_by_permissions from .permissions into src/contextactions/utils/__init__.py 2026年06月20日 12:44:14 +02:00
LICENSE add LICENSE 2024年12月12日 12:07:53 +01:00
manage.py add project for testing 2026年06月11日 18:28:36 +02:00
pyproject.toml fix: 'django' version 5.2.15 is outdated (latest: 6.0.6) 2026年06月11日 18:32:36 +02:00
README.md add information on how to use this project to README.md 2026年06月22日 09:35:37 +02:00

Django Context-Actions

Quickly link to other pages of your django application.

Features

  • Simple definition of links to other pages
  • Static or dynamic definition of ContextActions
  • Filters out links to views that the user is not allowed to access
  • Automatically uses the most recent next parameter of GET queries

Setup

from django.utils.translation import gettext_lazy as _
from django.views.generic import TemplateView
from contextactions.contextactions import ContextAction
from contextactions.mixins import ContextActionsMixin
class MyView(
 ContextActionsMixin,
 TemplateView,
):
 context_actions = [
 ContextAction(
 name='my_app:my_view',
 label=_('my human readable translated link text'),
 ),
 ]
 template_name = 'my_template.html'

In your template include the provided context actions template...

{% include 'contextactions/contextactions.html' %}

or implement you own using view.get_context_actions

{% for action in view.get_context_actions %}
 <a href="{% if action.url %}{{ action.url }}{% else %}{% url action.name %}{% endif %}">{% if action.label %}{{ action.label }}{% else %}{{ action.url }}{% endif %}</a>
{% endfor %}