myapp#
What is myapp?#
myapp is a Django application.
- In Django:
A project = whole website (settings, config, deployment)
An app = one feature or module inside the project
- Examples of apps:
Blog
Accounts
Products
Orders
Payments
Here myapp is a feature container, not the whole site.
How to Create an App in Django#
Step0: Make sure you are in the right place#
You must be inside the Django project directory, where manage.py exists.
Example:
mysite/
βββ manage.py
βββ mysite/
Check:
ls
You should see:
manage.py
Step1: Activate your virtual environment#
If youβre using venv:
macOS / Linux
source djenv/bin/activate
Windows
djenv\Scripts\activate
You should see something like:
(djenv)
Step2: Create the Django app#
A Django app is created using python manage.py startapp appname, then registered in INSTALLED_APPS to become active.
Run:
python manage.py startapp myapp
- Replace myapp with your app name:
blog
accounts
products
orders
Step3: What Django creates for you#
After running the command, Django generates:
myapp/
βββ migrations/
β βββ __init__.py
βββ __init__.py
βββ admin.py
βββ apps.py
βββ models.py
βββ tests.py
βββ views.py
This is a complete app skeleton.
Step4: Register the app#
Open:
mysite/settings.py
Find:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
...
]
Add your app:
INSTALLED_APPS = [
...
'myapp',
]
If you skip this step, Django will ignore your app.
Step5: Run the server to verify#
python manage.py runserver
Open:
http://127.0.0.1:8000/
If no errors β app created successfully
Step6: (Optional) Create app URLs#
Create a file:
myapp/urls.py
Add:
from django.urls import path
from . import views
urlpatterns = [
path('', views.home, name='home'),
]
Then include it in project urls.py:
from django.urls import path, include
urlpatterns = [
path('', include('myapp.urls')),
]
Step7: (Optional) Create your first view#
In myapp/views.py:
from django.http import HttpResponse
def home(request):
return HttpResponse("Hello from myapp")
Refresh browser
Naming rules for apps#
- Good names:
blog
accounts
payments
orders
- Bad names:
MyApp
Test-App
django
- Use:
lowercase
no spaces
no hyphens
Common mistakes to avoid#
Running startapp outside project
Forgetting to add app to INSTALLED_APPS
Using uppercase names
Creating one giant app
Where myapp lives#
mysite/
βββ myapp/ β application (features live here)
βββ mysite/ β project configuration
βββ manage.py
Why Django uses apps#
- Django apps give you:
Modular design
Reusability
Clean separation of concerns
Easier testing
Enterprise-scale structure
A real Django project often has many apps.
myapp folder structure#
myapp/
βββ migrations/
βββ __init__.py
βββ admin.py
βββ apps.py
βββ models.py
βββ tests.py
βββ views.py
We will explain each file separately, check left sidebar navigation.
How myapp connects to the project#
Nothing in myapp works until you register it.
In settings.py:
INSTALLED_APPS = [
...
'myapp',
]
- Once added:
Models are recognized
Migrations work
Admin shows your models
URLs can connect to views
What myapp is responsible for#
- myapp can contain:
Database tables (models)
Business logic
Views (HTTP handling)
Admin customization
Tests
API logic
- It does NOT:
Configure settings
Run servers
Handle deployment
Project vs App#
Project (mysite) |
App (myapp) |
|---|---|
Settings |
Features |
URLs (root) |
URLs (feature-level) |
ASGI / WSGI |
Views |
Deployment |
Business logic |
Real-world example#
- Think like this:
π’ Project = Mall
π¬ Apps = Shops
Mall handles security, electricity, layout
Each shop handles its own products and sales
How Django uses myapp#
Request flow:
Browser β urls.py β views.py β models.py β response
All of that happens inside the app.
Very important rule#
One app = one responsibility
- Good:
accounts
orders
payments
- Bad:
One giant app doing everything
What weβll cover next#
- Next pages in this exact order:
migrations/
__init__.py (app-level)
apps.py
models.py
admin.py
views.py
tests.py