Django contact form tutorial

preview_player
Показать описание
EMAIL_HOST = ''your host'
EMAIL_HOST_USER = 'your user'
EMAIL_HOST_PASSWORD = 'your password'
EMAIL_PORT = 587
EMAIL_USE_TLS = True

from django import forms

class ContactForm(forms.Form):
name = forms.CharField(max_length=100,label=_(u'Your name'))
email = forms.EmailField(max_length=200, label=_(u'Your email address'))
body = forms.CharField(label=_(u'Your message'))

from_email = settings.DEFAULT_FROM_EMAIL

recipient_list = [mail_tuple[1] for mail_tuple in settings.MANAGERS]

def message(self):
)

def get_context(self):
raise ValueError("Cannot generate Context from invalid contact form")

def get_message_dict(self):
raise ValueError("Message cannot be sent from invalid contact form")
message_dict = {}
for message_part in ('from_email', 'message', 'recipient_list', 'subject'):
attr = getattr(self, message_part)
message_dict[message_part] = attr() if callable(attr) else attr
return message_dict

def save(self, fail_silently=False):

path('index/', get_name, name='index'),

from .forms import ContactForm

def get_name(request):
# if this is a POST request we need to process the form data
# create a form instance and populate it with data from the request:
form = ContactForm(request.POST)
# check whether it's valid:
# ...
# redirect to a new URL:
contact_name = request.POST.get('name', '')
contact_email = request.POST.get('email', '')
form_content = request.POST.get('body', '')

# Email the profile with the
# contact information
context = {
'contact_name': contact_name,
'contact_email': contact_email,
'form_content': form_content,
}

email = EmailMessage(
"Nueva forma de contacto registrada",
content,
contact_email,
headers = {'Reply-To': contact_email }
)
return redirect('/landingPage/index/')

# if a GET (or any other method) we'll create a blank form
else:
form = ContactForm()

Nombre de contacto:
{{ contact_name }}

e-mail:
{{ contact_email }}

Mensaje:
{{ form_content|safe|striptags }}

{% csrf_token %}

***REMEMBER***
django doesnt render the form, you still need to add the form in your html
Рекомендации по теме
Комментарии
Автор

You was witing in spanish in a video about cleanning keyboard and i see your channel and you are doing english videos.... lmao.

observator.