{"id":9685,"library":"django-slack","title":"django-slack Integration","description":"django-slack provides easy-to-use integration between Django projects and the Slack group chat and IM tool. It simplifies sending messages and notifications to Slack channels. Currently at version 5.19.0, it is actively maintained with regular updates, typically released multiple times a year to follow Django versions or introduce new features and fixes.","status":"active","version":"5.19.0","language":"en","source_language":"en","source_url":"https://github.com/lambdacomputer/django-slack","tags":["django","slack","notification","integration","messaging"],"install":[{"cmd":"pip install django-slack","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Used for making HTTP requests to the Slack API and webhooks.","package":"requests","optional":false}],"imports":[{"note":"The primary function for sending messages; import path changed from 'django_slack' in older versions.","wrong":"from django_slack import slack_message","symbol":"slack_message","correct":"from slack import slack_message"},{"note":"A lower-level function for sending messages, typically used when direct API calls are preferred over the high-level 'slack_message' which can use webhooks or tokens.","symbol":"slack_notify","correct":"from slack.api import slack_notify"},{"note":"Used for constructing structured Slack message objects programmatically.","symbol":"Message","correct":"from slack.messages import Message"}],"quickstart":{"code":"import os\nfrom django.conf import settings\nimport django\n\n# Configure Django settings minimally for a standalone script\n# In a full Django project, these settings would be in your settings.py\nif not settings.configured:\n    settings.configure(\n        INSTALLED_APPS=['slack'],\n        # Replace with your actual Slack Incoming Webhook URL\n        # or SLACK_TOKEN if using the full API\n        SLACK_WEBHOOK_URL=os.environ.get(\n            'SLACK_WEBHOOK_URL',\n            'https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX' # Placeholder URL\n        ),\n        # A secret key is required by Django for settings.configure\n        SECRET_KEY='a-secret-key-for-demo-purposes-only',\n        DEBUG=True,\n        # Minimal database and timezone settings for django.setup() to work\n        DATABASES={'default': {'ENGINE': 'django.db.backends.sqlite3', 'NAME': ':memory:',}},\n        USE_TZ=True,\n        TIME_ZONE='UTC',\n    )\n    django.setup()\n\nfrom slack import slack_message\n\n# Send a simple message to a specific Slack channel\n# Ensure the channel exists and your webhook/token has permissions\nslack_message(\n    text='Hello from Django-Slack! This is a quickstart test message.',\n    channel='#general', # Replace with your target channel name\n    username='DjangoBot',\n    icon_emoji=':rocket:'\n)\n\nprint(\"Attempted to send message to Slack. Check your configured channel.\")\n# Note: Actual delivery depends on correct Slack configuration and network access.\n","lang":"python","description":"This quickstart demonstrates how to send a simple Slack message. It includes a minimal Django settings configuration to make the snippet runnable outside of a full Django project (e.g., as a standalone script). In a real Django project, ensure 'slack' is in `INSTALLED_APPS` and `SLACK_WEBHOOK_URL` (or `SLACK_TOKEN`) is defined in your `settings.py`."},"warnings":[{"fix":"Migrate to the new `slack.signals.message_sending` and `slack.signals.message_sent` signals, which provide similar functionality with a different signature. Review the official documentation for updated signal usage.","message":"The `slack.signals.slack_message_pre_send` and `slack.signals.slack_message_post_send` signals were removed in version 5.0.0.","severity":"breaking","affected_versions":">=5.0.0"},{"fix":"Update your `settings.py` to use `SLACK_WEBHOOK_URL`. The old setting might still work as a fallback but is considered deprecated.","message":"The `SLACK_INCOMING_WEBHOOK_URL` setting was renamed to `SLACK_WEBHOOK_URL` for consistency in version 5.0.0.","severity":"breaking","affected_versions":">=5.0.0"},{"fix":"Ensure all imports use `from slack import ...` (e.g., `from slack import slack_message`) instead of `from django_slack import ...`.","message":"The primary import path for modules changed from `django_slack` to `slack` in version 4.0.0.","severity":"gotcha","affected_versions":">=4.0.0"},{"fix":"`SLACK_WEBHOOK_URL` is for incoming webhooks (simpler setup, limited features), while `SLACK_TOKEN` is for using the full Slack Web API (requires an app token, provides more control). Choose based on your integration needs and configure the respective setting in `settings.py`.","message":"Understanding the difference between `SLACK_TOKEN` and `SLACK_WEBHOOK_URL` is crucial for correct setup.","severity":"gotcha","affected_versions":"All"}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"Change all imports from `from django_slack import ...` to `from slack import ...` (e.g., `from slack import slack_message`).","cause":"Attempting to import from the old package name 'django_slack' after upgrading to version 4.0.0 or later.","error":"ModuleNotFoundError: No module named 'django_slack'"},{"fix":"Add `SLACK_TOKEN = 'xoxb-YOUR-SLACK-BOT-TOKEN'` or `SLACK_WEBHOOK_URL = 'https://hooks.slack.com/services/...'` to your `settings.py`.","cause":"Neither a Slack API token nor an incoming webhook URL has been configured in your Django settings.","error":"ImproperlyConfigured: Either SLACK_TOKEN or SLACK_WEBHOOK_URL must be defined in your settings."},{"fix":"Update your signal connections to use the new `slack.signals.message_sending` or `slack.signals.message_sent` signals. Consult the documentation for their updated signatures.","cause":"You are trying to connect to a signal that was removed or renamed in django-slack version 5.0.0.","error":"AttributeError: module 'slack.signals' has no attribute 'slack_message_pre_send'"},{"fix":"Verify your `SLACK_WEBHOOK_URL` or `SLACK_TOKEN` is correct. Check network connectivity from your server to Slack. Ensure no firewall rules are preventing outgoing HTTPS connections to `hooks.slack.com` or `slack.com`.","cause":"Indicates a network issue, an incorrect `SLACK_WEBHOOK_URL` or `SLACK_TOKEN`, or a firewall blocking outbound requests to Slack.","error":"requests.exceptions.ConnectionError: HTTPSConnectionPool(host='hooks.slack.com', port=443): Max retries exceeded with url: ..."}]}