Home > Articles > Open Source > Python

  • Print
  • + Share This
This chapter is from the book

This chapter is from the book

Creating the Blog Application

Now that we have a project, we can create applications (or “apps” in Django-speak) within it. To create our blog app, we’ll use manage.py again.

./manage.py startapp blog   # or ".\manage.py startapp blog" on win32

It’s just as simple as starting a project. Now we have a blog directory inside our project directory. Here’s what’s in it, first in Unix format, and then in a screenshot of Windows Explorer (see Figure 2.3).

$ ls -l blog/
total 16
-rw-r--r--   1 pbx  pbx   0 Jun 26 20:33 __init__.py
-rw-r--r--   1 pbx  pbx  57 Jun 26 20:33 models.py
-rw-r--r--   1 pbx  pbx  26 Jun 26 20:33 views.py
Figure 2.3

Figure 2.3 mysite\blog folder on Win32

Like your project, your app is a package too. The models.py and views.py files have no real code in them; they’re merely placeholders. For our simple blog, in fact, we don’t need to touch the dummy views.py file at all.

To tell Django this new app is part of your project, you need to edit settings.py (which we can also refer to as your “settings file”). Open your settings file in your editor and find the INSTALLED_APPS tuple near the bottom. Add your app in dotted module form to that tuple in a line that looks like this (note the trailing comma):


Django uses INSTALLED_APPS to determine the configuration of various parts of the system, including the automatic admin application and the testing framework.

  • + Share This
  • 🔖 Save To Your Account