Skip to content

Instantly share code, notes, and snippets.

@droposhado

droposhado/index.html

Last active Apr 2, 2016
Embed
What would you like to do?
Happy theme for Mezzanine
{% extends "base.html" %}
{% block meta_title %}{% endblock %}
{% block title %}Welcome!{% endblock %}
{% block main %}
<!-- Contact Section -->
<section id="contact">
<div class="container">
<div class="row">
<div class="col-lg-12 text-center">
<h2>Contact</h2>
<h4>Want to know more about the project or part?
Send us a message!</h4>
<hr class="star-primary">
</div>
</div>
<div class="row">
<div class="col-lg-8 col-lg-offset-2">
<form name="sentMessage" id="contactForm" novalidate>
{% csrf_token %}
<div class="row control-group">
<div class="form-group col-xs-12 floating-label-form-group controls">
<label>Name</label>
<input type="text" class="form-control" placeholder="Name" id="name" required data-validation-required-message="Please, fill this field!">
<p class="help-block text-danger"></p>
</div>
</div>
<div class="row control-group">
<div class="form-group col-xs-12 floating-label-form-group controls">
<label>E-mail</label>
<input type="email" class="form-control" placeholder="E-mail" id="email" required data-validation-required-message="Please, fill this field!">
<p class="help-block text-danger"></p>
</div>
</div>
<div class="row control-group">
<div class="form-group col-xs-12 floating-label-form-group controls">
<label>Phone</label>
<input type="tel" class="form-control" placeholder="Phone number" id="phone" required data-validation-required-message="Please, fill this field!">
<p class="help-block text-danger"></p>
</div>
</div>
<div class="row control-group">
<div class="form-group col-xs-12 floating-label-form-group controls">
<label>Message</label>
<textarea rows="5" class="form-control" placeholder="Message" id="message" required data-validation-required-message="Please, fill this field"></textarea>
<p class="help-block text-danger"></p>
</div>
</div>
<br>
<div id="success"></div>
<div class="row">
<div class="form-group col-xs-12">
<button type="submit" class="btn btn-success btn-lg">Send</button>
</div>
</div>
</form>
</div>
</div>
</div>
</section>
{% endblock %}
from django.conf.urls import url
from . import views
urlpatterns = [
url(r'contact/$', views.contact, name='contact')
]
from django.shortcuts import render
from django.core.mail import send_mail
from django.http import JsonResponse
def contact(request):
if request.method == 'POST':
name = request.POST.get('name', '')
phone = request.POST.get('phone', '')
email = request.POST.get('email', '')
message = request.POST.get('message', '')
if name and email and message:
return JsonResponse({
"status": 500,
"text": "Please, Fill in all fields"
})
message_full = """Name: {}
Phone: {}
E-mail: {}
Message: {}""".format(name, phone, email, message)
try:
send_mail("Contact: {}".format(name),
message_full,
email,
['flavertonrodrigues@gmail.com'],
fail_silently=False)
except:
return JsonResponse({
"status": 500,
"text": "An error occurred while sending"
})
return JsonResponse({
"status": 200,
"text": "Sent with success!"
})
else:
return JsonResponse({
"status": 404,
"text": "Incorrect data submission method"
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment