首页 > Linux操作系统 > Linux操作系统 > A Data Migration for Every Django Project

A Data Migration for Every Django Project

原创 Linux操作系统 作者:jieforest 时间:2012-06-20 09:54:52 0 删除 编辑
How to use a South data migration to avoid accidentally sending emails from


Consider the following snippet from Django's docs [1] for sending a confirmation email:


from django.contrib.sites.models import Site
from django.core.mail import send_mail

def register_for_newsletter(request):
    current_site = Site.objects.get_current()
        'Thanks for subscribing to %s alerts' %,
        'Thanks for your subscription. We appreciate it.\n\n-The %s team.' %,
        'editor@%s' % current_site.domain,
    )Here the domain for the email sender is taken from the 'current site' instance, which is controlled by Django's 'Sites' framework and accessible by a custom method on the manager of the Site model.

By default, a Site instance is created with domain and display name '' and you have to correct these values. This is often done by hand using the admin suite.

However, as with any manual change, it's easy to forget and you'll often find Django projects sending email from Highly embarrassing.

来自 “ ITPUB博客 ” ,链接:,如需转载,请注明出处,否则将追究法律责任。

上一篇: NoSQLUnit 0.3.0发布
请登录后发表评论 登录


  • 博文量
  • 访问量