How to Create a Django App: Step-by-Step Guide
To create a Django app, run
python manage.py startapp appname inside your Django project directory. This command creates a new folder with files to build your app's features.Syntax
The command to create a Django app is python manage.py startapp appname.
python manage.py: Runs Django management commands.startapp: The command to create a new app.appname: The name you choose for your app folder.
This command must be run inside your Django project folder where manage.py is located.
bash
python manage.py startapp appname
Example
This example shows creating a Django app named blog. It creates a folder blog with files like views.py, models.py, and apps.py to start building your app.
plaintext
django_project/
├── manage.py
├── django_project/
│ ├── __init__.py
│ ├── settings.py
│ ├── urls.py
│ └── wsgi.py
└── blog/
├── __init__.py
├── admin.py
├── apps.py
├── migrations/
│ └── __init__.py
├── models.py
├── tests.py
└── views.pyOutput
A new folder named 'blog' is created with the standard app files.
Common Pitfalls
Common mistakes when creating a Django app include:
- Running
startappoutside the project folder, causingmanage.pynot found errors. - Forgetting to add the new app to
INSTALLED_APPSinsettings.py, so Django won't recognize it. - Using invalid app names with spaces or special characters.
Always check your current directory and app name before running the command.
bash
Wrong:
$ python startapp blog
# Error: 'manage.py' not found
Right:
$ python manage.py startapp blog
# Creates the app folder successfullyQuick Reference
Summary tips for creating a Django app:
- Run
python manage.py startapp appnameinside your project folder. - Choose simple, lowercase app names without spaces.
- Add your app to
INSTALLED_APPSinsettings.pyafter creation. - Use the created files like
views.pyandmodels.pyto build your app features.
Key Takeaways
Run 'python manage.py startapp appname' inside your Django project folder to create an app.
Always add your new app to 'INSTALLED_APPS' in 'settings.py' to activate it.
Use simple, valid names for your app to avoid errors.
The created app folder contains files to start building your app's logic and views.