New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

django-simple-notification

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

django-simple-notification

Simple user notification management for the Django web framework

  • 1.0.5
  • PyPI
  • Socket score

Maintainers
1

install

pip install django-simple-notification

Usage

1. create notification events


from notifications.handlers import send_message

send_message('Mahmoud Liked your post', user, 'post_like')

Explain

# function interface
send_message(message:str, user:User, type:str)

# logic behind it
message: the text message to be sent to the user
user: an instance of User model (the one who will recieve the notification)
type: is a notification tag or type (you should create difrrent types in your system for different events)

2.fetch notifications using REST APIs

notifications/all/:GET : get all the notifications



notifications/mark/:PUT : mark all notifications as read

img_1.png


notifications/unread/:GET: get all unread notifications

img_2.png

3.how the client side recieve the message from the server via websocket

img.png

configration

Note: make sure that django channels is up and running and also you django serves under ASGI check this url to configure django channels in your project

in settings.py

INSTALLED_APPS = [
    ...
    'channels', # django channels needs to be installed
    'notifications', # our package
    ...   
]

SIMPLE_NOTIFICATION_SETTINGS = {
    'receive_handler_path': 'custom_module.custom_py_file.custom_receive_handler',
}

in urls.py

path('api/v1/notifications/', include('notifications.urls')),

in asgi.py

from notifications import routing

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'demo_project.settings')

application = ProtocolTypeRouter({
    'http': get_asgi_application(),
    'websocket': AuthMiddlewareStack(
        URLRouter(
            routing.websocket_urlpatterns
        )
    ),
})

run make migrate:

python manage.py migrate

Keywords

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc