Django Lesson 2: Setup & First Project

🐍 Django CourseLesson 2 of 10 · 20% complete

Let’s create a Django project from scratch. Django has a specific project structure that becomes very familiar.

# Create virtual environment
python -m venv venv
# Activate (Mac/Linux):
source venv/bin/activate
# Activate (Windows):
venv\Scripts\activate

# Install Django
pip install django

# Create project
django-admin startproject myblog .

# Create an app (Django splits projects into apps)
python manage.py startapp posts

# Run development server
python manage.py runserver
# Open: http://127.0.0.1:8000

Project Structure

myblog/
├── manage.py              # command-line utility
├── myblog/
│   ├── settings.py        # all configuration
│   ├── urls.py            # root URL routing
│   └── wsgi.py            # production server
└── posts/                 # your app
    ├── models.py          # database models
    ├── views.py           # view functions
    ├── urls.py            # app-level routing
    ├── admin.py           # admin configuration
    └── templates/         # HTML templates

Register Your App

# myblog/settings.py
INSTALLED_APPS = [
    "django.contrib.admin",
    "django.contrib.auth",
    "django.contrib.contenttypes",
    "posts",  # add your app here!
]

🏋️ Practice Task

Create a Django project “mysite” with an app called “blog”. Register the blog app. Run the server and visit http://127.0.0.1:8000 — you should see the Django welcome page.

💡 Hint: If you see “The install worked successfully! Congratulations!” page, you’re set up correctly.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *