在我的Django应用程序中,我想自定义在用户请求重置密码时发送给用户的电子邮件。我将这些模板保存在项目 templates
目录中。
/templates/email/password_reset/password_reset.html
用于HTML电子邮件/templates/email/password_reset/password_reset.txt
用于普通电子邮件/templates/email/password_reset/password_reset_subject.txt
在我的网址模式中,我有......
urlpatterns = [
...
url('^password_reset/$', auth_views.password_reset,
{
'template_name': 'accounts/reset_password.html',
'email_template_name': 'email/password_reset/password_reset.txt',
'html_email_template_name': 'email/password_reset/password_reset.html',
'subject_template_name': 'email/password_reset/password_reset_subject.txt'
},
name='password_reset'),
...
]
但是,Django仍使用默认密码重置模板发送电子邮件。我错过了一些明显的东西吗?感谢。
答案 0 :(得分:2)
事实证明,我在网址中偶然定义了auth_views.password_reset
两次。删除副本修复了问题。
答案 1 :(得分:1)
应该如此简单(docs)。
public class ProductModel
{
public int ID { get; set; }
[Required(ErrorMessage = "Required")]
[Index("ItemNumber", 1, IsUnique = true)]
[Display(Name = "Item #")]
public int itemNumber { get; set; }
[Required(ErrorMessage = "Required")]
[Display(Name = "Product")]
[MaxLength(50)]
public String product { get; set; }
[Display(Name = "Description")]
[MaxLength(500)]
public String description { get; set; }
[DefaultValue(true)]
[Display(Name = "Active?")]
public bool active { get; set; }
[Display(Name = "Image Name")]
public String imageName { get; set; }
[Display(Name = "PDF Name")]
public String PDFName { get; set; }
[Display(Name = "Category(s)")]
public virtual ICollection<CategoryModel> ProductCategories { get; set; }
public IEnumerable<SelectListItem> CategorySelectList { get; set; }
//public ICollection<CategoryModel> CategoryList { get; set; }
public virtual BrochureModel Brochure { get; set; }
public IEnumerable<SelectListItem> BrochureList { get; set; }
public static IEnumerable<SelectListItem> getCategories(int id = 0)
{
using (var db = new ProductContext())
{
List<SelectListItem> list = new List<SelectListItem>();
var categories = db.Categories.ToList();
foreach (var cat in categories)
{
SelectListItem sli = new SelectListItem { Value = cat.ID.ToString(), Text = cat.categoryName };
if (id > 0 && cat.ID == id)
{
sli.Selected = true;
}
list.Add(sli);
}
return list;
}
}
public ProductModel()
{
active = true;
}
}