Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- widok:
- def contact(request):
- title = "Contact me"
- form = ContactForm(request.POST or None)
- if form.is_valid():
- form_email = form.cleaned_data.get("email")
- form_message = form.cleaned_data.get("message")
- form_full_name = form.cleaned_data.get("full_name")
- subject = "Site contact form"
- from_email = settings.EMAIL_HOST_USER
- to_email = [from_email, ]
- contact_message = " %s: %s via %s" % (form_full_name, form_message, form_email)
- send_mail(subject,
- contact_message,
- from_email,
- [to_email],
- fail_silently=False)
- context = {
- "title": title,
- "form": form,
- }
- return render(request, "forms.html", context)
- forms:
- class ContactForm(forms.Form):
- full_name = forms.CharField(max_length=24)
- email = forms.EmailField()
- message = forms.CharField()
- settings:
- EMAIL_HOST = 'smtp.gmail.com'
- EMAIL_HOST_USER = 'mojmail@mail.com'
- EMAIL_HOST_PASSWORD = 'moje_haslo'
- EMAIL_PORT = 587
- EMAIL_USE_TLS = True
- '''
- if using gmail, you will need to unlock captcha to enable django
- to send for you:
- https://accounts.google.com/displayunlockcaptcha
- '''
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement