2

(first of all sorry for my bad english)

i need to know if exist any way to set some values in the settings files using some data stored in the database.

for example the Mail config

EMAIL_HOST = ''
EMAIL_HOST_USER = ''
EMAIL_HOST_PASSWORD = ''
EMAIL_PORT = 587
EMAIL_USE_TLS = True

i like to fill that variables using the data that i save in the model that i have for settings in the Company App.

but like the settings files are readed before the server starts then i don't know if exist any way to do this.

hope you can understand me.

Thanks!

marcosgue
  • 627
  • 3
  • 8
  • 24

2 Answers2

1

the email host must be hardcoded,if you what set something related to you own logic,you can try django-constance.or you can try to read setting from txt,i don't konw if it will be useful,but it's a worthwhile method.

Ykh
  • 7,567
  • 1
  • 22
  • 31
0

As far as I know, the Django settings are supposed to be immutable. There are multiple reasons for this, the most obvious being that Django is not aware of the server's execution model (prefork / multi-threaded).

Also, you can't load the settings themselves from a Django model because the settings need to be loaded before you can use anything in the ORM. This means you cannot set your email address from database , you need to set email in settings.py file itself (hardcoded).

Akash Wankhede
  • 618
  • 6
  • 15
  • Thats what i thinking... but today i have to change my mail server, and then i think... what if some client want's or must to do the same maybe i can add some company config and put there the mail values... maybe there are some app for mails that can be configured from database... i don't know! – marcosgue May 27 '17 at 04:14
  • 1
    @marcosgue, I have found same question like this, https://stackoverflow.com/questions/22281865/dynamic-django-mail-configuration. Hope it helps you. – Akash Wankhede May 27 '17 at 04:58
  • It means, you can use send_mail, you'll have to create your own email backend which uses your custom settings and then pass it to send_mail in the connection attribute. – Akash Wankhede May 27 '17 at 05:00