Starting with Django: The App

This week I want to put down some foundations of an app. Currently my site only has a blog on it, though I do want to add some other functionality to it.

Last week I talked about the basics of the project, which is kind of like the folder that you put a bunch of documents in. It makes it easier to find a collection of apps.

So the big difference between starting a project is that starting a project uses the django-admin script. An app on the other hand will use the existing project you have already created. Remember how we got a manage.py file? Well that contains all the scripts we would use once the project has been created. Basics like startapp, run server, makemigrations, migrate are all a part of the manage.py.

As you likely realised, our first command will be the startapp and the syntax is like this:

python manage.py startapp <name_of_app>


There are a few files created by this, and we go more in depth in future posts, but lets look at the basics.

You should now have a folder of name_of_app (or whatever you actually called it)
Inside that folder you will have the following files:

  • admin
  • apps
  • models
  • tests
  • views
There are a few files missing, such as urls and folders for migrations, templates, and possibly static and media folders, depending on your end requirements.

Its important to understand that you can realistically create as many apps as you want, just make sure they make sense to you.

You can also abstract out functions like a class. In the tutorial I did for my blog, the user side of things was abstracted out to its own app, which gives you the ability to define it as its own persona in a sense but still utitlise it as a core of your site.

Don't forget, one you create an app, you have to add it back to your project. Lets make that next weeks article though.

Comments

Popular Posts