LoginSignup
0
0

More than 3 years have passed since last update.

Djangoを使ったWEBアプリケーションの開発【アプリケーション追加編】

Last updated at Posted at 2020-09-17

初期設定編の続き

アプリケーションを追加しよう

今回、「posts」というアプリケーションを追加することにしました。
(※アプリケーション名は、複数形にするのが慣例のようです。)

$ python3.6 manage.py startapp posts

これを実行することで、project1フォルダにpostsフォルダが作成されます。

postsとプロジェクトの紐付け

postsフォルダ内に作成されたapps.pyの中を確認すると下記の内容になっています。

apps.py

from django.apps import AppConfig


class PostsConfig(AppConfig):
    name = 'posts'

このPostConfigクラスをプロジェクトから呼び出せるように設定を行います。
settings.pyを開き「INSTALLED_APPS」に追記します。
「フォルダ名.ファイル名.クラス名」として追加していきます。

settings.py
INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'posts.apps.PostsConfig', #新しく追加する行
]

(※このとき「 , 」を付けておくと良いかもしれません。)

0
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0