Django: Getting Started Transcripts
Chapter: Your First Django App
Lecture: Apps vs projects
Login or
purchase this course
to watch this video and the rest of the course contents.
0:00
You may recall that. I was careful about avoiding the word application earlier. The reason for this is Django divides the world into two things.
0:08
Projects and apps. A project is your web server stuff. An app is a module inside of that project.
0:16
To avoid confusion, I try not to use the word application while talking about Django unless I mean a Django app,
0:22
you'll be writing your first Django app in a minute. You can also download third party apps and plug them into your project from here on
0:29
In when you hear app think module Django apps contain the code that outputs HTML
0:35
They have a well defined naming structure and the files inside your app need to
0:40
follow this. Not all the files are necessary for all apps but most of them are pretty common for starters is the ap file.
0:48
This defines some metadata for your Django app and is a key part of how Django figures out what apps are in a project.
0:56
Django is roughly defined around the model, view controller presentation concept very roughly actually.
1:02
It kind of blurs the lines around the controller part. This idea separates out the model of your data from the view used to present it
1:09
The views file inside of an app contains yep, you guessed it. The views used to present your content.
1:17
There are several different ways of defining views. The simplest of which is a function that returns some HTML.
1:24
There are two common places for unit tests in a Django project. Either at the project level or grouped in with the app.
1:31
I tend to favor the project level unless I'm writing a package herbal app that I'm
1:35
shipping separately. But if you want to associate your tests with your app, they go inside of test stop I inside of the app.
1:43
The model part of a model view controller represents the data in your software.
1:47
Django has a rich mechanism for mapping classes to content in a database. This kind of feature is known as an O.
1:54
RM or object relational model. The models file is where you locate the classes that define the data storage in your Django app.
2:03
A lot of web applications center around the Crud. That's capital C capital R capital U capital D create read, update and delete operations of data.
2:14
The data is defined in classes in the model's file, but you often have to create a lot of pages for managing the creation and editing
2:22
of the data that goes in the models. Consider user management. You need pages for creating users changing their info,
2:29
resetting their passwords. Deleting the list goes on to simplify this process. Django comes with a powerful tool called the Django admin.
2:38
The admin is a series of pages for your models with a little extra code. You get data management almost for free.
2:46
The admin file is where the admin code for your models in your Django app belong When you created your Django project,
2:53
you saw the Earl's file in the inner alexandria directory. This is the main place to map you RLS to code that outputs content.
3:01
You can also optionally define an Earl's file. For your Django app, you have to add some code to the project level Earl's
3:08
file to use an app level Earl's file, but is often a good idea to keep your app specific URL.
3:14
Mapping these together. The final part of the app that I'll mention for now is
3:18
the migrations directory. Django comes with a mechanism for doing database migrations as you adapt
3:24
your models over time, the corresponding tables in the database will need to change columns may get added or removed, tables may get added or removed,
3:31
etcetera. The migrations directory contains code that helps you manage these kinds of activities.
3:37
In a later chapter, I'll run you through all of the specifics.