LoginSignup
1
2

More than 5 years have passed since last update.

Djangoでウェブアプリ - 準備

Last updated at Posted at 2018-09-05

Djangoを使ってウェブアプリを作ります
まずは環境を準備します

  • このページで作成されたDjango環境はここからダウンロード可能です

1. Django環境を用意します

  • virtualenvなどで仮想環境を用意し、pip install djangoでDjango2.0をインストールします

  • 下記のようなコマンドで仮想環境へ入ります

source ve18/bin/activate
  • 新たにdjangoプロジェクトを開始(作成)します。ここでは「northernlights」というプロジェクトを作成しています
django-admin startproject northernlights
  • lsコマンドでnorthernlightsが作成されていることを確認し、cdコマンドでそのフォルダへ入ります。northernlightsフォルダにmanage.pyファイルとnorthernlightsサブフォルダがあることを確認します
(ve18) MacBook:180905a tohru$ ls
northernlights

(ve18) MacBook:180905a tohru$ cd northernlights/

(ve18) MacBook:northernlights tohru$ ls
manage.py   northernlights
  • 下記のコマンドで新しいアプリを作成します。ここではpenguinというアプリを作成しています
python manage.py startapp penguin
  • Penguinアプリが作成されていることを確認します
(ve18) MacBook:northernlights tohru$ ls
manage.py   northernlights  penguin

2. 必要な設定をします

  • 作成したアプリを登録します。northernlightsフォルダのsettings.pyを開き、INSTALLED_APPSpenguinを追加します
INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'penguin',
]

合わせて必要な設定を行います

LANGUAGE_CODE = 'ja_JP'

TIME_ZONE = 'Asia/Tokyo'

USE_I18N = True

USE_L10N = True

USE_TZ = False

3. 稼働を確認します

  • 下記コマンドでDjangoを起動します
(ve18) MacBook:northernlights tohru$ python manage.py runserver 
Performing system checks...

System check identified no issues (0 silenced).

You have 14 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions.
Run 'python manage.py migrate' to apply them.

September 05, 2018 - 02:34:58
Django version 2.0.5, using settings 'northernlights.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
[05/Sep/2018 02:35:05] "GET / HTTP/1.1" 200 16348
[05/Sep/2018 02:35:05] "GET /static/admin/css/fonts.css HTTP/1.1" 200 423
[05/Sep/2018 02:35:05] "GET /static/admin/fonts/Roboto-Bold-webfont.woff HTTP/1.1" 200 82564
[05/Sep/2018 02:35:05] "GET /static/admin/fonts/Roboto-Regular-webfont.woff HTTP/1.1" 200 80304
[05/Sep/2018 02:35:05] "GET /static/admin/fonts/Roboto-Light-webfont.woff HTTP/1.1" 200 81348
  • ブラウザでlocalhost:8000を開き、Djangoが起動されていることを確認します

スクリーンショット 2018-09-05 12.05.05.png

1
2
0

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
1
2