A Data Migration for Every Django Project
How to use a South data migration to avoid accidentally sending emails from example.com.
Problem
Consider the following snippet from Django's docs [1] for sending a confirmation email:
from django.core.mail import send_mail
def register_for_newsletter(request):
current_site = Site.objects.get_current()
send_mail(
'Thanks for subscribing to %s alerts' % current_site.name,
'Thanks for your subscription. We appreciate it.\n\n-The %s team.' % current_site.name,
'editor@%s' % current_site.domain,
[user.email]
)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 'example.com' 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 editor@example.com. Highly embarrassing.
Problem
Consider the following snippet from Django's docs [1] for sending a confirmation email:
CODE:
from django.contrib.sites.models import Sitefrom django.core.mail import send_mail
def register_for_newsletter(request):
current_site = Site.objects.get_current()
send_mail(
'Thanks for subscribing to %s alerts' % current_site.name,
'Thanks for your subscription. We appreciate it.\n\n-The %s team.' % current_site.name,
'editor@%s' % current_site.domain,
[user.email]
)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 'example.com' 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 editor@example.com. Highly embarrassing.
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/301743/viewspace-733299/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 雲資料遷移(Cloud Data Migration,CDM)Cloud
- Django筆記二十之手動編寫migration檔案Django筆記
- Django的Project和App的區別DjangoProjectAPP
- JavaScript every()JavaScript
- Python,Django建立web專案project和應用appPythonDjangoWebProjectAPP
- 2.3.4 Migration of an Existing ApplicationAPP
- JS中some、every、map、filterJSFilter
- make:migration 的騷操作
- Laravel migration 逆向生成工具Laravel
- milvus-migration安裝使用
- 遷移執行緒migration執行緒
- javascript forEach無法break,使用every代替JavaScript
- 簡述forEach()、map()、filter()、every()、some()的用法Filter
- Migration Of An Oracle Database Across OS Platforms [ID 733205.1]OracleDatabaseROSPlatform
- Laravel migration (資料庫遷移) 的使用Laravel資料庫
- 陣列的forEach,map,filter,reduce,reduceRight,every,some方法陣列Filter
- Prettier your projectProject
- Wireless Communication ProjectProject
- SAP Spartacus SplitViewComponent Migration 的一個具體例子View
- Sekai Project的世界AIProject
- Gradle Project Sync FailedGradleProjectAI
- idea--Project StructureIdeaProjectStruct
- Generating Pods project failedProjectAI
- Project Three: Simple WorldProject
- Code Project精彩分享Project
- Big Data and Data Warehousing
- 解決eclipse的 Invalid project description. overlaps the location of another project: 問題EclipseProject
- Based UE_Project NotesProject
- 中文Project Office X 啟用安裝包「Project Office X 破解下載」Project
- Django(2) - Django模板Django
- Project Management - 2) Estimate Your WorkProject
- Project facet Java version 1.8 is not supportedProjectJava
- Tinykv Project2 隨筆Project
- Project2021,專案管理Project專案管理
- MYSQL錯誤程式碼:1248 Every derived table must have its own alias 解決MySql
- Django(33)Django操作cookieDjangoCookie
- Cannot uninstall 'ipaddress'. It is a distutils installed project and thusiPadProject
- RAG Project with Ollama and LangChain via Gradio InterfaceProjectLangChain
- Dynamic Web Project option missing in Eclipse KeplerWebProjectEclipse