I'm using Django as backend and Yeoman as frontend. I'm new to both. My frontend local server is running on localhost:9000
, and my backend server is running on localhost:8000
.
I just built an email sender application following the Django tutorial. It is working perfectly and consists of:
A form:
class ContactForm(forms.Form):
name = forms.CharField()
email = forms.EmailField()
telephoneNr = forms.IntegerField()
message = forms.CharField(widget=forms.Textarea)
A view:
from django.core.mail import send_mail
from django.shortcuts import render, render_to_response
from django.http import HttpResponseRedirect, HttpResponse
from mailsender.forms import ContactForm
def contact(request):
if request.method == 'POST':
form = ContactForm(request.POST)
if form.is_valid():
success = True
name = form.cleaned_data['name']
email = form.cleaned_data['email']
telephoneNr = form.cleaned_data['tlf']
message= form.cleaned_data['melding']
receiverEmail = ['somewhere@example.com']
text = message +'\n'+name +'\n'+str(telephoneNr)
send_mail('Contact form', beskjed, email, receiverEmail)
return render(request,"result.html")
else:
form = ContactForm(
return render(request, 'contactform.html', {'form':form})
And my HTML:
<h1>Contact us</h1>
{% if form.errors %}
<p style="color: red;">
Please correct the error{{ form.errors|pluralize }} below.
</p>
{% endif %}
<form action="" method="post">
<table>
{{ form.as_p }}
</table>
{% csrf_token %}
<input type="submit" value="Submit">
</form>
If I visit localhost:8000/contactform
, the contact form is displayed just as I want, and it does send emails.
I need help figuring out how to hook up this view to the Yeoman frontend - as searching the Internetz (and SO) leads me to the path of confusion. Should I use Tastypie? I really want to keep this logic in the backend. Any help pointing me in the right direction is greatly appreciated.