- Python (version 3.7 or higher)
- Django (version 3.x or higher)
- pip (Python package installer)
- Virtual environment tool (optional but recommended)
-
Clone the Repository:
https://github.com/AntoJebi7/Django_Essentials_with_SQL_DB.git
-
Create a Virtual Environment (Optional but recommended):
python3 -m venv env source env/bin/activate # On Windows use `env\Scripts\activate`
-
Install Dependencies: Install Django and other dependencies from
requirements.txt
:pip install -r requirements.txt
-
Create a Django Project: If you haven’t already created the Django project:
django-admin startproject myproject .
-
Run Migrations:
python manage.py migrate
-
Run the Development Server:
python manage.py runserver
Access the server at
http://127.0.0.1:8000/
.
-
Create an App:
python manage.py startapp myapp
-
Register the App: Add your app to the
INSTALLED_APPS
insettings.py
:INSTALLED_APPS = [ # Other apps... 'myapp', ]
-
Create Initial Migrations:
python manage.py makemigrations myapp
-
Apply Migrations:
python manage.py migrate
This project demonstrates a user authentication system in Django, including registration and login functionality with password hashing. This README outlines the setup process, database configuration, and important Django commands.
- Introduction
- SQL Database Creation
- Django Setup
- User Registration Process
- Login Process
- Password Hashing
- Django Commands for Migration
- Important Topics
This project sets up a Django application that allows users to register and log in. The registration process includes password hashing for security. Successful login redirects users to a designated blog page.
-
Install MySQL:
- Ensure MySQL Server and MySQL Workbench are installed on your system.
-
Create a Database:
-
Open MySQL Workbench and run the following SQL command to create a new database:
CREATE DATABASE mydatabase;
-
-
Configure Django to Use MySQL:
- Update your Django project's
settings.py
file to configure the database settings.
- Update your Django project's
-
Install Dependencies:
-
Install Django and MySQL client library using pip:
pip install django mysqlclient
-
-
Create a Django Project:
-
Create a new Django project:
django-admin startproject myproject
-
-
Create a Django App:
-
Inside the project directory, create a new Django app:
python manage.py startapp registration
-
-
Define the Model:
- In the
registration
app, define theRegistration
model with fields for username, password, etc.
- In the
-
Create a Registration Form:
- Create a Django form for user registration in the
registration/forms.py
file.
- Create a Django form for user registration in the
-
Implement the Registration View:
- Create a view to handle user registration, validate the form, and save user details.
-
Create a Registration Template:
- Design an HTML template for the registration form.
-
Implement the Login View:
- Create a view to handle user login, validate username and password, and handle redirects.
-
Create a Login Template:
- Design an HTML template for the login form.
-
Hash Passwords During Registration:
- Use Django’s
make_password
to hash passwords before saving them to the database.
- Use Django’s
-
Verify Passwords During Login:
- Use Django’s
check_password
to verify user passwords during login.
- Use Django’s
-
Create Migrations:
-
Generate migration files for your models:
python manage.py makemigrations
-
-
Apply Migrations:
-
Apply the migrations to create database tables:
python manage.py migrate
-
-
Create a Superuser (optional):
-
Create a superuser account to access the Django admin interface:
python manage.py createsuperuser
-
- Password Hashing: Ensures passwords are stored securely in the database.
- User Authentication: Validates user credentials during login.
- Django Migrations: Manage changes to the database schema.