SHARE
TWEET

contact

Md_Zahid_Hassan Sep 23rd, 2019 95 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Contact(models.Model):
  2.     name = models.CharField(max_length=50)
  3.     sub = models.CharField(max_length=50)
  4.     email = models.EmailField()
  5.     message = models.TextField()
  6.  
  7.  
  8. form.py
  9.  
  10. class ContactForm(forms.ModelForm):
  11.     class Meta:
  12.         model = Contact
  13.         fields = ['name', 'sub', 'email', 'message']
  14.  
  15. view function
  16.  
  17. def contact_info(request):
  18.     form = ContactForm(request.POST or None)
  19.     if form.is_valid():
  20.         instance = form.save(commit=False)
  21.         instance.save()
  22.         return redirect('index')
  23.     else:
  24.        form = ContactForm()
  25.  
  26.     return render(request, 'index.html', {'form': form})
  27.  
  28.  
  29.  
  30.  
  31. <form  action="" method="POST">
  32.              {% csrf_token %}
  33.              {{form.as_p }}
  34.   <button class="btn btn-common" id="submit" type="submit">Send Message</button>
  35.                 </form>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top