What is an app
First of all, we have created a Django project called Toodoo. And a Django project usually exist of multiple apps. It's not necessarily easy to explain what a Django app is, so I will give you an example.
The project we're going to build in this series will be a task manager. It's not a very complicated project, so we will probably only have one app called "Task". The Task app will consist of a few files. We will have one file where we "describe" to the database what information we want to store there, this is called a "model". There will also be a file where we create views, a folder for the templates and similar. We will go through each of them when we have created the first one.
Let's say that we also had user profiles for the project. Then we would have one more app for that. It's not impossible to have everything in one really big app, but that's really not good practice.
Creating the app
To create the app, we need to run a command. Be sure to be in the same folder as the "manage.py" file.
$ python manage.py startapp task
And that's it! You have not created your first Django app. But even though we have created it, Django doesn't actually know that it exists. So we need to append it to a list in the "settings.py" file.
INSTALLED_APPS = [ ... 'task', ]
As you can see, there are already a few apps in the list. These comes built into Django. It's apps for handling security, caching, messages and similar. Don't worry, we will come back to them later in this series.
So just append 'task' to the end of the list, and you're good to go :-)
What are the different files
This file is empty, but it still has a function. It makes Python treat this folder as a module, so it's easy to reference the files inside it and similar.
Here, we can register database model with the build in admin interface that Django comes with. We can also add configurations to them, so we get search, filtering and similar.
This file is for configurations for the app.
This is where we define what information we store in the database. For example that we want a title for the task, a status, a description and similar.
In this file, we can write tests for the app. To make sure that everything is working as it should.
A view is used to get information from the database, and render it in a template.
Just like the files in the root folder, this might be a little bit information overload. But in the next part, we will finally start coding and I promise that everything will start making more sense then.
Table of contents
- 1. Introduction
- 2. Installation and setup
- 3. How things work
- 4. The first Django app
- 5. Your first view
- 6. Your first template
- 7. Testing our site
- 8. Extending templates
- 9. Your first model
- 10. The admin interface
- 11. Showing contents from the model
- 12. Another app (category)
- 13. Connecting two models
- 14. Show list of categories
- 15. Category detail page