Skip to main content

A Django app to handle un-authenticated user enquiries.

Project description

A Django app to facilitate website ‘contact us’ functionality.

Detailed documentation is in the “docs” directory.

Quick start

  1. Add "contact_us_tools" to your INSTALLED_APPS setting:

    INSTALLED_APPS = [
        # ...,
        "contact_us_tools",
    ]
  2. Set up the necessary settings for sending emails. For example, if gmail is your chosen host:

    EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
    EMAIL_HOST = 'smtp.gmail.com'
    EMAIL_USE_TLS = True
    EMAIL_PORT = 587
    EMAIL_HOST_USER = "example@gmail.com"
    EMAIL_HOST_PASSWORD = "exmample"

    See the django documentation https://docs.djangoproject.com/en/5.2/topics/email/#email-backends

  3. Extend the BaseMessage model and set the BUSINESS_NAME and COPYRIGHT_YEAR attributes:

    from contact_us_tools.models import AbstractBaseMessage
    
    class Message(AbstractBaseMessage):
        BUSINESS_NAME = "My Business Name"
        COPYRIGHT_YEAR = 2025

    BUSINESS_NAME is your business or website name to be displayed in the automatic-reply email and COPYRIGHT_YEAR is the year to be displayed with the copyright notice in the email.

    For further configuration of the BaseMessage model, consult the docs https://django-contact-us-tools.readthedocs.io/en/latest/index.html.

  4. Register the new model to your admit site:

    from django.contrib import admin
    admin.site.register(Message)
  5. Create a new form or extend BaseContactUsForm and add the model attribute to the Meta class:

    from contact_us_tools.forms import BaseContactUsForm
    
    class ContactUsForm(BaseContactUsForm):
       class Meta(BaseContactUsForm.Meta):
          model = Message
  6. Create a html template for the ‘contact us’ form. For example:

    <form action="" method="POST">
        {% csrf_token %}
    
        <legend>Contact Us</legend>
        <small>Got any questions? Fill out this form to reach out.</small>
    
        {{ form }}
    
        <button type="submit">Submit</button>
    </form>
  7. Extend BaseContactUsView, making sure to overwrite form_class and template_name with the form and html template you just created, as well as supplying a success url:

    from django.urls import reverse
    from contact_us_tools.views import BaseContactUsView
    
    class ContactUsView(BaseContactUsView):
        form_class = ContactUsForm
        template_name = 'template_name'
    
        def get_success_url(self):
            return reverse('success_url_name')

    For further configuration of BaseContactUsView, consult the docs https://django-contact-us-tools.readthedocs.io/en/latest/index.html.

  8. Add a URL pattern to handle the rendering of the form:

    urlpatterns = [
        # ...,
        path('contact-us', ContactUsView.as_view(), name='contact-us'),
    ]
  9. Run python manage.py makemigrations then python manage.py migrate to create the models.

  10. Start the development server and visit the relevant url to test the ‘contact us’ form.

  11. Visit the admin site to view the resulting addition to the relevant database table.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_contact_us_tools-0.1.3.tar.gz (10.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_contact_us_tools-0.1.3-py3-none-any.whl (11.4 kB view details)

Uploaded Python 3

File details

Details for the file django_contact_us_tools-0.1.3.tar.gz.

File metadata

  • Download URL: django_contact_us_tools-0.1.3.tar.gz
  • Upload date:
  • Size: 10.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.8

File hashes

Hashes for django_contact_us_tools-0.1.3.tar.gz
Algorithm Hash digest
SHA256 98b211cd6486ded158744705f1976f28cb8c4476e141f8fe3353d2555b0d6650
MD5 067212e8984dbe638ec493d448b37008
BLAKE2b-256 1c87e9e10beacc5099cfaed4898e0753a7fd5dc7d64d9183a570b4fbd282ebac

See more details on using hashes here.

File details

Details for the file django_contact_us_tools-0.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for django_contact_us_tools-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 3b420fc7666d14d287916bc04c9d19f547fa47814a0bd6e8f1ae6aeed5b0255f
MD5 b13ba595b31f2bfffbc9130534c25e58
BLAKE2b-256 7c7f11bf5cfec8d82aa4f482b786647c0571e92d6a5d44d09f83b24e2cc7d20e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page