Home Backend Development Python Tutorial Building a Secure Anonymous Feedback System with Django, Twilio, and Pinata

Building a Secure Anonymous Feedback System with Django, Twilio, and Pinata

Oct 06, 2024 am 06:13 AM

In this guide, I will walk you through building a Secure Anonymous Feedback System using Django, Twilio for SMS notifications, Pinata for secure media uploads, and TailwindCSS for responsive styling. By the end of this tutorial, you will have a fully functional feedback system where users can submit feedback, optionally upload media, and receive SMS notifications—all with security and privacy in mind.

Demo: Live Link

Key Features:

  • Anonymous Feedback Submission: Users can submit feedback or support requests anonymously.
  • Secure Media Uploads: Users can upload media files securely via Pinata, stored on IPFS.
  • Twilio SMS Notifications: Automatically sends SMS confirmation to users via Twilio.
  • Responsive UI: Styled with TailwindCSS for a seamless, modern design.

Technologies Used:

  • Django: Backend framework for the feedback system.
  • Twilio: Handles SMS notifications.
  • Pinata: Provides IPFS-based secure media storage.
  • TailwindCSS: For responsive frontend styling.

Step 1: Project Setup and Dependencies

1.1. Create and Set Up a Virtual Environment
Start by setting up your project environment. Ensure you have Python installed and set up a virtual environment:


python3 -m venv venv
source venv/bin/activate


Copy after login

On Windows:


venv\Scripts\activate


Copy after login

Install the necessary packages:


pip install django twilio python-decouple requests gunicorn


Copy after login

1.2. Start a Django Project
Initialize a new Django project and app:


django-admin startproject config .
python manage.py startapp feedback


Copy after login

Step 2: Build the Feedback Submission System

2.1. Create a Feedback Model
Define a model to store feedback submissions in feedback/models.py:


from django.db import models

class Feedback(models.Model):
    message = models.TextField()
    sender_email = models.EmailField()
    sender_phone = models.CharField(max_length=15)
    media_url = models.URLField(null=True, blank=True)
    created_at = models.DateTimeField(auto_now_add=True)

    def __str__(self):
        return f"Feedback from {self.sender_email}"


Copy after login

This model captures feedback, email, phone number, and optional media URLs.

2.2. Create Views for Handling Feedback and SMS Notifications
In feedback/views.py, create views to process feedback and send SMS notifications:


from django.shortcuts import render
from django.http import HttpResponse
from .models import Feedback
from twilio.rest import Client
from django.conf import settings
import requests

def upload_to_pinata(file):
    url = "https://api.pinata.cloud/pinning/pinFileToIPFS"
    headers = {
        'pinata_api_key': settings.PINATA_API_KEY,
        'pinata_secret_api_key': settings.PINATA_SECRET_API_KEY,
    }
    files = {'file': file}
    response = requests.post(url, files=files, headers=headers)
    return response.json().get('IpfsHash')

def submit_feedback(request):
    if request.method == 'POST':
        message = request.POST.get('message')
        sender_email = request.POST.get('sender_email')
        sender_phone = request.POST.get('sender_phone')
        file = request.FILES.get('media_file', None)

        media_url = None
        if file:
            media_url = upload_to_pinata(file)

        feedback = Feedback.objects.create(
            message=message,
            sender_email=sender_email,
            sender_phone=sender_phone,
            media_url=media_url
        )

        # Send SMS using Twilio
        client = Client(settings.TWILIO_ACCOUNT_SID, settings.TWILIO_AUTH_TOKEN)
        client.messages.create(
            body=f"Feedback received from {sender_phone}: {message}",
            from_=settings.TWILIO_PHONE_NUMBER,
            to=sender_phone
        )

        return HttpResponse("Feedback submitted successfully!")

    return render(request, 'feedback_form.html')


Copy after login

This view handles form submissions, uploads optional media to Pinata, and sends SMS using Twilio.

2.3. Creating the Feedback Form
Create an HTML form to submit feedback. In your templates folder, create feedback_form.html:


{% load static %}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Submit Feedback</title>
    <link href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css" rel="stylesheet">
</head>
<body class="bg-gray-100">
    <div class="container mx-auto px-4 py-6">
        <h1 class="text-3xl font-bold text-center">Submit Feedback</h1>
        <form method="POST" action="" enctype="multipart/form-data" class="bg-white p-6 rounded shadow-md">
            {% csrf_token %}
            <div class="mb-4">
                <label for="message" class="block text-lg font-semibold">Your Feedback</label>
                <textarea name="message" id="message" class="w-full p-2 border rounded" required></textarea>
            </div>
            <div class="mb-4">
                <label for="sender_email" class="block text-lg font-semibold">Your Email</label>
                <input type="email" name="sender_email" id="sender_email" class="w-full p-2 border rounded" required>
            </div>
            <div class="mb-4">
                <label for="sender_phone" class="block text-lg font-semibold">Your Phone Number</label>
                <input type="tel" name="sender_phone" id="sender_phone" class="w-full p-2 border rounded" required>
            </div>
            <div class="mb-4">
                <label for="media_file" class="block text-lg font-semibold">Upload Media (Optional)</label>
                <input type="file" name="media_file" id="media_file" class="w-full p-2 border rounded">
            </div>
            <div class="text-center">
                <button type="submit" class="bg-blue-500 text-white px-4 py-2 rounded">Submit</button>
            </div>
        </form>
    </div>
</body>
</html>


Copy after login

Building a Secure Anonymous Feedback System with Django, Twilio, and Pinata
Image of the Front end

Building a Secure Anonymous Feedback System with Django, Twilio, and Pinata
Image of Pinata Dashboard showing the files uploaded

Step 3: Configuring Twilio and Pinata

3.1. Set Up Environment Variables
Create a .env file in your project’s root directory to store sensitive information like Twilio and Pinata API keys:


SECRET_KEY=your-django-secret-key
DEBUG=True

TWILIO_ACCOUNT_SID=your_twilio_account_sid
TWILIO_AUTH_TOKEN=your_twilio_auth_token
TWILIO_PHONE_NUMBER=your_twilio_phone_number

PINATA_API_KEY=your_pinata_api_key
PINATA_SECRET_API_KEY=your_pinata_secret_api_key


Copy after login

Make sure to add .env to your .gitignore file so it won’t be pushed to GitHub:


.env


Copy after login

3.2. Update settings.py to Use Environment Variables
Use python-decouple to securely load environment variables from the .env file:


from decouple import config

SECRET_KEY = config('SECRET_KEY')
DEBUG = config('DEBUG', default=False, cast=bool)

TWILIO_ACCOUNT_SID = config('TWILIO_ACCOUNT_SID')
TWILIO_AUTH_TOKEN = config('TWILIO_AUTH_TOKEN')
TWILIO_PHONE_NUMBER = config('TWILIO_PHONE_NUMBER')

PINATA_API_KEY = config('PINATA_API_KEY')
PINATA_SECRET_API_KEY = config('PINATA_SECRET_API_KEY')


Copy after login

Step 4: Pushing to GitHub

4.1. Initialize Git and Push to GitHub

  1. Initialize a Git repository in the root of your project:

git init
git add .
git commit -m "Initial commit for feedback system"


Copy after login
  1. Add your GitHub repository as a remote and push your project:

<p>git remote add origin https://github.com/yourusername/feedback-system.git<br>
git push -u origin main</p>

Copy after login




Conclusion

In this tutorial, you’ve built a secure anonymous feedback system using Django, Twilio for SMS notifications, and Pinata for media uploads. You’ve also learned how to push your project to GitHub and secure sensitive information using environment variables. This system ensures privacy while enabling users to submit feedback and receive SMS notifications.

Feel free to expand the system further by adding more features or enhancing security. If you found this guide helpful, share your feedback or questions in the comments!

The Repo to the Project can be found here: Repo

The above is the detailed content of Building a Secure Anonymous Feedback System with Django, Twilio, and Pinata. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to solve the permissions problem encountered when viewing Python version in Linux terminal? How to solve the permissions problem encountered when viewing Python version in Linux terminal? Apr 01, 2025 pm 05:09 PM

Solution to permission issues when viewing Python version in Linux terminal When you try to view Python version in Linux terminal, enter python...

How to avoid being detected by the browser when using Fiddler Everywhere for man-in-the-middle reading? How to avoid being detected by the browser when using Fiddler Everywhere for man-in-the-middle reading? Apr 02, 2025 am 07:15 AM

How to avoid being detected when using FiddlerEverywhere for man-in-the-middle readings When you use FiddlerEverywhere...

How to efficiently copy the entire column of one DataFrame into another DataFrame with different structures in Python? How to efficiently copy the entire column of one DataFrame into another DataFrame with different structures in Python? Apr 01, 2025 pm 11:15 PM

When using Python's pandas library, how to copy whole columns between two DataFrames with different structures is a common problem. Suppose we have two Dats...

How to teach computer novice programming basics in project and problem-driven methods within 10 hours? How to teach computer novice programming basics in project and problem-driven methods within 10 hours? Apr 02, 2025 am 07:18 AM

How to teach computer novice programming basics within 10 hours? If you only have 10 hours to teach computer novice some programming knowledge, what would you choose to teach...

How does Uvicorn continuously listen for HTTP requests without serving_forever()? How does Uvicorn continuously listen for HTTP requests without serving_forever()? Apr 01, 2025 pm 10:51 PM

How does Uvicorn continuously listen for HTTP requests? Uvicorn is a lightweight web server based on ASGI. One of its core functions is to listen for HTTP requests and proceed...

How to solve permission issues when using python --version command in Linux terminal? How to solve permission issues when using python --version command in Linux terminal? Apr 02, 2025 am 06:36 AM

Using python in Linux terminal...

How to get news data bypassing Investing.com's anti-crawler mechanism? How to get news data bypassing Investing.com's anti-crawler mechanism? Apr 02, 2025 am 07:03 AM

Understanding the anti-crawling strategy of Investing.com Many people often try to crawl news data from Investing.com (https://cn.investing.com/news/latest-news)...

See all articles