Installing Django
Let's get Django running on your machine. The first step is installing it via pip โ Python's package manager. Trust me, it's simpler than you think.
pip install django
That's it. One command and Django is installed. You can verify it worked by checking the version:
python -m django --version
Creating Your First Project
Now that Django is installed, let's create a new project. Django comes with a handy command-line tool called django-admin that handles project scaffolding.
django-admin startproject mysite
This creates a mysite directory with all the boilerplate you need. Navigate into it and you'll see a manage.py file and another mysite folder inside.
Running the Development Server
Django includes a lightweight development server so you can preview your work without setting up Apache or Nginx. Start it with:
python manage.py runserver
Open your browser and head to http://127.0.0.1:8000/. You should see the Django welcome page. The server auto-reloads when you change code, so you never have to restart it manually during development.
Keeping Track of Dependencies
When you work on real projects, you'll install third-party packages. It's good practice to track them in a requirements.txt file so others can reproduce your environment.
pip freeze > requirements.txt
Anyone who clones your project can then run pip install -r requirements.txt and get the exact same setup. Don't skip this step โ it'll save you from "works on my machine" problems later.