Django Contact Us App with Ajax Django.How

Author avatar wrote on 26/05/2022

1.Create contact_us app by tiping in our terminal :


python manage.py startapp contact_us

2.Copy to models.py this code

3.Add to settings.py this app:


INSTALLED_APPS = [
    ...
    'contact_us.apps.ContactUsConfig',
    .... 
]

4.Create urls.py inside this app and copy this code there:


from django.urls import path

from . import views

urlpatterns = [
    path('', views.index, name='contact_us')
]

5.Add to our main urls.py new urlpatter:


`urlpatterns = [
    ....
    path('contact_us/', include('contact_us.urls')),
    ....
] + static(settings.MEDIA_URL, document_root = settings.MEDIA_ROOT)

6.Copy to views.py this code:

7.Copy to admin.py this code:


from django.contrib import admin
from django_summernote.admin import SummernoteModelAdmin

from .models import Contact_us

class Contact_usAdmin(SummernoteModelAdmin):
    summernote_fields = ('message',)
    list_display = ('name', 'email', 'phone', 'subject', 'department','date')
    list_display_links = ('name', 'email', 'phone')
    search_fields = ('department', 'date')
    list_per_page = 20

admin.site.register(Contact_us,Contact_usAdmin)

8.Create folder templates/contact_us and index.html inside this new folder. Copy html code from this file:

Add this file to our js folder, and run “python”

NOTICE: don’t forget to include this file in our base.html file, simply add: