Objective
To create a simple web-based password manager that allows users to securely store and manage their passwords.
Table of Contents
Requirements
- Intermediate understanding of Python
- Familiarity with HTML, CSS, and basic web development
- Python 3.x installed
- Django installed (
pip install Django
)
Packages Needed
Verify that Django can be seen by Python, type python
from your shell. Then at the Python prompt, try to import Django:
>>>import django
>>>print(django.get_version())
4.2
Steps
Step 1: Set Up Django Project and App
Open shell terminal and create a new Django project:
django-admin startproject PasswordManager
Inside the project directory, create a new app:
python manage.py startapp mypasswords
In root project folder “PasswordManager”, following three items will be created:
+ mypasswords
+ PasswordManager
mangage.py
Step 2: Configure Database
Django comes with SQLite, so you don’t need to install it separately. Update PasswordManager/settings.py
to make sure your app is included in INSTALLED_APPS
.
# PasswordManager/settings.py
INSTALLED_APPS = [
# ...
'mypasswords',
]
Step 3: Create Models
Define the models in models.py
inside your app folder.
# mypasswords/models.py
from django.db import models
class Password(models.Model):
website = models.CharField(max_length=100)
username = models.CharField(max_length=100)
password = models.CharField(max_length=100)
Run the migrations to create the database schema:
python manage.py makemigrations
python manage.py migrate
Step 4: Create Views and Templates
- Create a new folder called
templates
inside your app folder and add an HTML fileindex.html
. - In
views.py
, add the logic for fetching and storing passwords.
# mypasswords/views.py
from django.shortcuts import render, redirect
from .models import Password
def index(request):
if request.method == 'POST':
website = request.POST['website']
username = request.POST['username']
password = request.POST['password']
new_entry = Password(website=website, username=username, password=password)
new_entry.save()
return redirect('index')
else:
passwords = Password.objects.all()
return render(request, 'index.html', {'passwords': passwords})
Step 5: Create Forms in HTML
Add form fields in index.html
to input website, username, and password.