NelsonLabs
Django/Setup & First Project

Setup & First Project

Django projects have a specific structure โ€” a project container with multiple apps inside it. Understanding this structure before you start prevents a lot of confusion later.

Setting up a Django project
bash
# Create and activate a virtual environment first (always!)
python -m venv venv
source venv/bin/activate    # Mac/Linux
venvScriptsactivate        # Windows

# Install Django
pip install django

# Create a project (note the dot โ€” creates in current directory)
django-admin startproject myproject .

# Project structure:
# manage.py          โ† command-line utility for Django
# myproject/
#   __init__.py
#   settings.py      โ† all project configuration
#   urls.py          โ† top-level URL routing
#   wsgi.py          โ† production server entry point

# Run the development server
python manage.py runserver
# Visit http://127.0.0.1:8000 โ€” you should see Django's welcome page
settings.py โ€” key settings to know
python
# myproject/settings.py (selected important settings)

DEBUG = True  # Set to False in production!

ALLOWED_HOSTS = ["localhost", "127.0.0.1"]
# Add your domain in production: ["nelsonlabs.dev", "www.nelsonlabs.dev"]

INSTALLED_APPS = [
    "django.contrib.admin",      # Admin interface
    "django.contrib.auth",       # Authentication system
    "django.contrib.contenttypes",
    "django.contrib.sessions",
    "django.contrib.messages",
    "django.contrib.staticfiles",
    # Your apps go here:
    "courses",                   # an app you create
]

DATABASES = {
    "default": {
        "ENGINE": "django.db.backends.sqlite3",
        "NAME": BASE_DIR / "db.sqlite3",
    }
}
# For PostgreSQL: ENGINE = "django.db.backends.postgresql"

STATIC_URL = "/static/"
MEDIA_URL  = "/media/"