Setting Up Django
Create a Django project and run the development server.
What you will learn
- Install Django in a virtual environment
- Create a project and app
- Run the dev server
Install & create
Use a virtual environment (so packages stay per-project), install Django with pip, then create a project.
python -m venv venv
# activate it: Windows: venv\Scripts\activate Mac/Linux: source venv/bin/activate
pip install django
django-admin startproject mysite
cd mysite
python manage.py runserverEach line in order: python -m venv venv creates a fresh virtual environment (a private box for this project’s packages). The activate line switches your terminal into that box — the command differs on Windows vs Mac/Linux. pip install django downloads Django into it. django-admin startproject mysite generates the project files, cd mysite moves into the new folder, and python manage.py runserver starts Django’s built-in development server.
Note: Output:
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
Open http://127.0.0.1:8000 in your browser — you’ll see Django’s welcome rocket. 🚀
Create an app
A Django project is split into apps (features). Create one with:
python manage.py startapp blogThen add "blog" to INSTALLED_APPS in mysite/settings.py.
Tip: Key files: manage.py (commands), settings.py (config), urls.py (routes), and inside each app: views.py, models.py, templates/.
Q. Which command starts the Django development server?
✍️ Practice
- Create a virtual environment, install Django, and start a project.
- Create an app and add it to INSTALLED_APPS.
🏠 Homework
- Run the dev server and view the welcome page in your browser.