如何访问 Django settings.py 中的模型或视图属性?
How to access model or views attributes in django settings.py?
我想更新我的电子邮件主机用户和密码,它存在于我的数据库中..我不知道如何更新它。但我在我的 settings.py 文件中提到了它。像这样,
EMAIL_HOST_USER = 'sender_mail@mail.com'
EMAIL_HOST_PASSWORD = 'passxxpass'....
i want to change it dynamically while updating my database.
我的 table 包含那些电子邮件 ID 和密码。它可能会根据用户需求动态变化。所以我想在 EMAIL_HOST_USER
和 PASSWORD
中做同样的事情...发送我的邮件..
你不应该这样做。设置适用于不会改变的事物;如果您的电子邮件是动态的,您应该在发送邮件时在视图中设置它。
你不能这样做。另外,你不应该这样做。
更好的方法是在您的数据库中创建 "Variable" table。
从 table 而不是设置文件访问值。
Django 的 send_mail
(我假设您正在使用)有两个参数 auth_user
和 auth_password
,您应该使用它们而不是尝试更改设置
send_mass_mail
等人也有这些参数
I Solved this by importing the below package in my view file,
import django.conf as conf ...
and using this i made the changes whatever i want dynamically like, for changing my EMAIL_HOST by using like this,
get_mail_data = mymodels.objects.get(head='Admin')
conf.settings.EMAIL_HOST_USER = get_mail_data.from_mail
above is just an example what i used in my code... there from_mail is field present in my table.
我想更新我的电子邮件主机用户和密码,它存在于我的数据库中..我不知道如何更新它。但我在我的 settings.py 文件中提到了它。像这样,
EMAIL_HOST_USER = 'sender_mail@mail.com'
EMAIL_HOST_PASSWORD = 'passxxpass'....
i want to change it dynamically while updating my database.
我的 table 包含那些电子邮件 ID 和密码。它可能会根据用户需求动态变化。所以我想在 EMAIL_HOST_USER
和 PASSWORD
中做同样的事情...发送我的邮件..
你不应该这样做。设置适用于不会改变的事物;如果您的电子邮件是动态的,您应该在发送邮件时在视图中设置它。
你不能这样做。另外,你不应该这样做。
更好的方法是在您的数据库中创建 "Variable" table。 从 table 而不是设置文件访问值。
Django 的 send_mail
(我假设您正在使用)有两个参数 auth_user
和 auth_password
,您应该使用它们而不是尝试更改设置
send_mass_mail
等人也有这些参数
I Solved this by importing the below package in my view file,
import django.conf as conf ...
and using this i made the changes whatever i want dynamically like, for changing my EMAIL_HOST by using like this,
get_mail_data = mymodels.objects.get(head='Admin')
conf.settings.EMAIL_HOST_USER = get_mail_data.from_mail
above is just an example what i used in my code... there from_mail is field present in my table.