i've been trying to figure out how to use ajax in my django for a while but I coulnt find a solution.
Here is my view.py:
from django.shortcuts import render, render_to_response, RequestContext, HttpResponseRedirect
from .forms import SignUpForm
from django.contrib import messages
# Create your views here.
def home(request):
form = SignUpForm(request.POST or None)
if form.is_valid():
save_it = form.save(commit=False)
save_it.save()
# messages.success(request, 'Thank you for joining!')
# return HttpResponseRedirect('/thank-you/')
return render_to_response("home.html",
locals(),
context_instance=RequestContext(request))
the is the model.py
from django.db import models
from django.utils.encoding import smart_unicode
# Create your models here.
class SignUp(models.Model):
first_name = models.CharField(max_length=120, null=True, blank=True)
last_name = models.CharField(max_length=120, null=True, blank=True)
email = models.EmailField()
timestamp = models.DateTimeField(auto_now_add=True, auto_now=False)
updated = models.DateTimeField(auto_now_add=False, auto_now=True)
def __unicode__(self):
return smart_unicode(self.email)
This is the html part
<form method='POST' action=''> {% csrf_token %}
{{ form.as_p }}
<input type='submit' class='btn btn-success'>
</form>
</div>
I've tried many method but none of them is working . can someone help
Im trying to log a thank you message after the user submitted their information. I want it stay still instead of refreshing. and how to use ajax to replace the built in error message when the email field is empty.
</div>