Django organises code into apps — modular components that handle specific features (blog, users, products).
Create an App
Bash
python manage.py startapp blogRegister the App
Python
# mysite/settings.py
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'blog', # add your app
]App Structure
Code
blog/
├── __init__.py
├── admin.py # Admin configuration
├── apps.py # App configuration
├── models.py # Database models
├── views.py # View functions
├── urls.py # URL patterns (create this)
├── tests.py # Tests
└── migrations/ # Database migrationsURL Configuration
Python
# blog/urls.py (create this file)
from django.urls import path
from . import views
urlpatterns = [
path('', views.post_list, name='post_list'),
path('post/<int:pk>/', views.post_detail, name='post_detail'),
]
# mysite/urls.py
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('blog.urls')),
]Common Commands
Bash
python manage.py runserver # Start dev server
python manage.py makemigrations # Create migrations
python manage.py migrate # Apply migrations
python manage.py createsuperuser # Create admin user
python manage.py shell # Interactive shell
python manage.py test # Run tests
python manage.py startapp appname # Create new appTips
- One Django project can have many apps — each app handles one feature.
- Always run
makemigrationsthenmigrateafter changing models. - Use
python manage.py shellfor debugging and testing queries.
Next: models.