Contact Us Feature in Django E-commerce Website
In this episode, we will be implementing the Contact Us feature in our Django E-commerce Website using Django. Let’s get started!
Setting Up the Contact Form
First, we need to create a new app for our contact form. Run the following command:
python manage.py startapp contact
Next, we need to create a model for our contact form. Open the models.py file in the contact app and add the following code:
from django.db import models class Contact(models.Model): name = models.CharField(max_length=100) email = models.EmailField() message = models.TextField()
Creating the Contact Form View
Now, we need to create a view for our contact form. Open the views.py file in the contact app and add the following code:
from django.shortcuts import render from .forms import ContactForm def contact_form(request): if request.method == 'POST': form = ContactForm(request.POST) if form.is_valid(): form.save() else: form = ContactForm() return render(request, 'contact_form.html', {'form': form})
Setting Up the Contact Form Template
Next, we need to create a template for our contact form. Create a new file called contact_form.html in the templates directory of the contact app and add the following code:
Contact Us Contact Us
{% csrf_token %} {{ form.as_p }}
Updating the URLs
Finally, we need to update the urls.py file in the contact app to include the contact form view:
from django.urls import path from .views import contact_form urlpatterns = [ path('contact/', contact_form, name='contact_form'), ]
That’s it! Now users can easily contact us through our new Contact Us feature on our Django E-commerce Website.
sir please can you add option like user can contact vendor and the information send first to admin then send to vendor
Hello Sir, Thank you for creating this amazing tutorial, well i came across this playlist very late.
It seems that you are working in django 3.2 version,
A small question, the code blocks or the codes you have used in here,
will these codes work in django ver. 4 too??
I am a beginner , apologies if this question is not appropriate..
Waiting for your reply
привет тут проблема я не могу купить твой файл я из Казахстана. В paystack когда надо выводит данные там только США и всё.
Very excellent sir, thank you sir
Please can you help me with Paystack integration?