1

I use django-rq in my Django application. Currently, I install django-rq with pip, then add the following content to mysite/settings.py:

INSTALLED_APPS += 'django_rq'

RQ_QUEUES = {
    'default': {
        'HOST': 'localhost',
        'PORT': 6379,
        'DB': 0,
        'DEFAULT-TIMEOUT': 360,
    }
}

This works well, but I want to distribute my application with an installation process as simple as possible. Is there a way to move the previous content of settings.py to my-app/apps.py or any other file distributed with my application?

Something like

from django.apps import AppConfig
from django.conf import settings

class MyAppConfig(AppConfig):
    name = 'myapp'

    def ready(self):
        settings.INSTALLED_APPS += 'django_rq'
        settings.RQ_QUEUES = {
            'default': {
                'HOST': 'localhost',
                'PORT': 6379,
                'DB': 0,
                'DEFAULT-TIMEOUT': 360,
            }
        }

This obviously won't work and is not recommended by the documentation, but you get the idea.

Dunatotatos
  • 1,706
  • 15
  • 25
  • So, if you want to have multiple settings for different environments, that you can create a settings folder and put a __init__.py in that folder. Make multiple setting files like dev1.py, dev2.py and based on the environment import that file in the __init__.py. – Sandeep Hukku Jun 04 '18 at 09:05
  • Thanks for the message, but I'm afraid this does not answer my question. What should I put in the `dev1.py` to add `django_rq` to the `INSTALLED_APPS` and configure the queues? – Dunatotatos Jun 04 '18 at 09:06
  • `INSTALLED_APPS += 'django_rq' settings.RQ_QUEUES = { 'default': { 'HOST': 'localhost', 'PORT': 6379, 'DB': 0, 'DEFAULT-TIMEOUT': 360, } }` – Sandeep Hukku Jun 04 '18 at 09:09
  • Does it mean the last snippet of my question actually works? It sounds strange, knowing that an imported `django.conf.settings` is a LazySettings, and is probably read-only. EDIT: I just tried, and I get an `ImproperlyConfigured` exception. It definitely does not work. – Dunatotatos Jun 04 '18 at 09:14

0 Answers0