Learning Django from Rajat Naroji sir
- Install
pip install django-browser-reload
- modify settings.py
INSTALLED_APPS = [
...existing code...
"django_browser_reload",
...existing code...
]
MIDDLEWARE = [
...existing code...
"django_browser_reload.middleware.BrowserReloadMiddleware",
...existing code...
]
- add to main urls.py
from django.urls import include, path
urlpatterns = [
...existing code...
path("__reload__/", include("django_browser_reload.urls")),
]
- finally run server
python manage.py runserver
-
Open shell
py manage.py shell
-
Inside shell, perform the following
from django.db import connection c = connection.curson() print(c)
-
If the connection is extablished, connection object will be returned else ERROR.
-
Download MySQL
- Go to MySQL Downloads and download the MySQL Installer.
-
Run the Installer:
- Run the downloaded installer.
- Choose the Server Only setup type (or another setup type that includes the MySQL Server).
- During installation, set a root password — remember this for later!
- Complete the installation.
-
Verify MySQL Installation:
- Open the MySQL Command Line Client from the Start menu.
- Enter the root password you set during installation.
- If connected successfully, you should see:
mysql>
-
This is the adapter that allows Django to connect to MySQL.
pip install mysqlclient
-
Create a Database in MySQL:
-
Open the MySQL Command Line Client and create a new database for your project:
CREATE DATABASE your_db_name;
-
-
Update
settings.py
in Django:-
In your Django project, open the
settings.py
file and configure theDATABASES
setting like this:DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', 'NAME': 'your_db_name', # The database you just created 'USER': 'root', # Default user 'PASSWORD': 'your_password', # Password you set during installation 'HOST': 'localhost', 'PORT': '3306', } }
-
-
This will apply all migrations and create the default Django tables (like
auth
,sessions
, etc.) in your MySQL database.python manage.py makemigrations python manage.py migrate
-
Run the development server:
python manage.py runserver
-
Go to
http://127.0.0.1:8000/
in your browser. -
If everything is set up correctly, your Django app should be running, and data will be stored in MySQL.
- You're now using MySQL with Django!