Posts

Showing posts from October, 2020

How to send email via Django?

To test whether emails are being sent through Django terminal, do the following checks. In settings.py  EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' DEFAULT_FROM_EMAIL = EMAIL_HOST_USER Run in interactive mode from Visual Studio Terminal python manage.py shell Import the EmailMessage module from django.core.mail import EmailMessage Send the email with below command. email = EmailMessage('Email Subject', 'This is for email Body', to=['xxxxxxxxxxxxx@xxxxxx.com']) email.send() If the above steps works successfully then your email account is configured to send emails.

capitalize() method in Python/Django

capitalize()  method in python/Django converts the first character of a string to capital l etter i.e.  uppercase . If the string has its first character as capital, then it returns the original string. name = "hello world"     print (name.capitalize())      result: Hello World name1 = "Hello World"     print (name1.capitalize())   result: Hello World name2 = "HELLO WORLD"     print (name2.capitalize())   result: Hello World name4 = "TRUE"     print (name4.capitalize())   result: True name5 = "FALSE"     print (name5.capitalize())   result: False

Comments in Python/Django

Single Line Comment:               # Single Line Comment Multi Line Comment:               """               This is for                 multi Line Comment               """