Commit c2832d90 authored by Myriam Begel's avatar Myriam Begel

Enregistre les messages envoyés

parent 41c15b6b
{% extends 'perso_app/base.html' %}
{% block body %}
<form method="post" action="">
<form method="post" action="{% url 'envoi' %}">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Envoyer" />
......
......@@ -5,4 +5,6 @@ urlpatterns = [
url(r'^$', views.accueil, name="accueil"),
url(r'^publications$', views.publications, name="publications"),
url(r'^contact$', views.contact, name="contact"),
url(r'^envoi$', views.envoiMessage, name="envoi"),
]
......@@ -15,3 +15,16 @@ def publications(request):
def contact(request):
context = {'form': ContactForm()}
return render(request, 'perso_app/contact.html', context)
def envoiMessage(request):
if request.method == 'POST':
form = ContactForm(request.POST)
if form.is_valid():
nom = form.cleaned_data['nom']
mail = form.cleaned_data['mail']
raison = form.cleaned_data['raison']
message = form.cleaned_data['message']
data = Contact(nom = nom, mail = mail, raison = raison, message = message)
data.save()
return HttpResponseRedirect(reverse('contact'))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment