Skip to main content

Django middleware for tracking recently visited pages

Project description

Recently Visited Page Middleware

A Django middleware to track and retrieve recently visited pages for authenticated users.

Installation

Install the package using pip:

pip install recently-visited-page-middleware==0.1

Add the app to your INSTALLED_APPS in your Django project's settings:

INSTALLED_APPS = [
    # ...
    'recently_visited_page_middleware',
    # ...
]

Add the middleware to your MIDDLEWARE:

MIDDLEWARE = [
    # ...
    'recently_visited_page_middleware.middleware.RecentlyVisitedPageMiddleware',
    # ...
]

Usage

Import the get_recently_visited_urls function in your views:

from recently_visited_page_middleware.utils import get_recently_visited_urls

In your class-based or function-based views, use the function to retrieve recently visited pages:

from rest_framework.views import APIView
from rest_framework.response import Response
from rest_framework import status
from rest_framework.permissions import IsAuthenticated

class RecentlyVisitedPagesView(APIView):
    permission_classes = [IsAuthenticated]

    def get(self, request):
        user_id = request.user.id

        recently_visited_urls = get_recently_visited_urls(user_id)

        response_data = {
            "status": "success",
            "message": "Recently Visited Pages Retrieved Successfully",
            "data": recently_visited_urls
        }

        return Response(response_data, status=status.HTTP_200_OK)

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

Built Distribution

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