Changing Django settings at runtime

前端 未结 7 1297
-上瘾入骨i
-上瘾入骨i 2020-11-30 05:09

I\'d like to expose some (app-specific) settings to the admin interface, so users can change them comfortably and also not have to restart Django.

How should I go ab

7条回答
  •  盖世英雄少女心
    2020-11-30 06:00

    Honestly I get more Django when I analyze his code. In version 1.4.5 did it (following the module below):

    • myproject\manage.py

    • django\core\management__init__.py ## method - execute_manager

    • django\conf__init__.py ## class - LazySettings; attr - _wrapped

    • django\utils\functional.py ## class LazyObject; important method - new_method_proxy

    Functional option, but it has its risks. In the python "_" considers the attribute as protected.

    from django.conf import settings
    
    settings._wrapped.INSTALLED_APPS = () ## *really work*
    

    In the following project: https://github.com/alexsilva/DJPlugins you can see this variable being modified at runtime. the idea of the project is already working.

提交回复
热议问题