Chapter 3 · 10 min read
Project vs App and runserver
Project vs App and runserver
Django has two words that confuse almost every beginner: project and app. In this chapter you will create both, start the development server, and register your app so that Django knows about it.
What you will learn
- The difference between a project and an app.
- How to create a project with
startprojectand an app withstartapp. - What each generated file is for.
- How to run the development server and stop it.
- How to register an app in
INSTALLED_APPS.
Project versus app
| Project | App |
|---|---|
| The whole website's configuration | One feature packaged as Python code |
| Holds settings, root URLs, server entry points | Holds models, views, templates, tests for one feature |
| There is one per website | A project contains many apps |
Example: the config folder in this course | Example: the blog folder in this course |
An app can be reused in other projects. For example, a "comments" app could be used by a blog and a news site. A project is the glue that selects which apps are installed and how URLs reach them.
manage.py: your control panel
manage.py is a small script in the project's root folder. Almost every command you run starts with python manage.py. It sets up the right settings and then runs a Django command such as runserver, migrate or test.
Step by step
Make sure you are in the myblog folder and the virtual environment is active (your prompt shows (.venv)).
1. Create the project
django-admin startproject config .
The dot at the end means "create it right here". Without the dot Django creates an extra nested folder, which confuses many beginners. The name config is the project package. Do not name a project django or test, because these clash with real Python packages.
2. Create the app
python manage.py startapp blog
3. Look at the layout
myblog/
manage.py
config/
__init__.py
settings.py
urls.py
asgi.py
wsgi.py
blog/
__init__.py
admin.py
apps.py
models.py
tests.py
views.py
migrations/
__init__.py
| File | Purpose |
|---|---|
config/settings.py | All project settings: installed apps, database, templates, static files |
config/urls.py | The root URL table |
config/wsgi.py and config/asgi.py | Entry points for production servers |
blog/models.py | Database tables for the app |
blog/views.py | Functions or classes that handle requests |
blog/admin.py | Registers models in the admin site |
blog/tests.py | Automated tests |
blog/migrations/ | Records of database changes |
4. Register the app
Open config/settings.py and add 'blog' to the end of INSTALLED_APPS:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'blog',
]
Django only looks for models, templates and static files inside apps listed here. If you forget this step, the app is silently ignored.
5. Create the built-in tables
python manage.py migrate
This creates a file named db.sqlite3 containing Django's own tables for users, sessions and more. You will learn migrations in detail in the chapter on models.
6. Start the development server
python manage.py runserver
You will see output similar to this:
Performing system checks...
System check identified no issues (0 silenced).
Django version 6.1, using settings 'config.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
Open http://127.0.0.1:8000/ in your browser. You should see Django's welcome page with a rocket. Stop the server by pressing Ctrl+C in the terminal.
About the development server
runserver is a lightweight server written in Python. It reloads automatically when you save a Python file. It is meant for development only: never use it to serve real visitors. In production you use a proper WSGI or ASGI server, which you will meet in the deployment chapter.
To use another port, add it to the command:
python manage.py runserver 8080
The server runs in your terminal and blocks it. Open a second terminal window (and activate the environment there) for other commands.
Check it works
- The terminal shows
Starting development server at http://127.0.0.1:8000/. - The browser shows the welcome page with the rocket.
python manage.py checkprintsSystem check identified no issues (0 silenced).
Exercises with solutions
Exercise 1: change the time zone
Set the project's time zone to Nepal's.
Solution. In config/settings.py change the line to:
TIME_ZONE = 'Asia/Kathmandu'
Save the file. The server reloads by itself. Time zone names come from the standard IANA database that Python's zoneinfo module understands.
Exercise 2: use another port
Run the server on port 8080 and open it in the browser.
Solution.
python manage.py runserver 8080
Open http://127.0.0.1:8080/. Stop it with Ctrl+C.
Exercise 3: break and fix the app registration
Remove 'blog' from INSTALLED_APPS, then run python manage.py check. Put it back.
Solution. The check still passes now, because the app has no models or templates yet. The mistake only shows up later, when templates or models in blog are ignored. That is why forgetting this step is dangerous: it fails silently. Add 'blog' again before continuing.
Common mistakes
- Running commands outside the folder that contains
manage.py. Symptom:can't open file manage.py. Fix:cdinto the folder first. - Forgetting to add the app to
INSTALLED_APPS. Models, templates and static files of the app are silently ignored. - Leaving off the dot in
startproject. You getmyblog/config/config/.... Delete the extra folder and run the command again with the dot. - Typing other commands in the terminal that runs the server. Open a second terminal.
- Port already in use. Another server is running. Stop it or choose a different port.
Key takeaways
- A project is the whole site's configuration; an app is one feature.
startproject config .andstartapp blogcreate the skeleton.- Add each app to
INSTALLED_APPS. python manage.py runserverstarts a development-only server; stop it with Ctrl+C.
Official links
- Tutorial part 1: https://docs.djangoproject.com/en/6.1/intro/tutorial01/
- django-admin and manage.py reference: https://docs.djangoproject.com/en/6.1/ref/django-admin/
