LoginSignup
21
33

More than 5 years have passed since last update.

Djangoの導入からサーバー起動まで

Last updated at Posted at 2017-04-01

Djangoとは

Pythonで実装されたWebアプリケーションフレームワーク。
簡単に複雑なデータベース主体の Web サイトを構築できる。

環境

  • CentOS
  • Python 3.5.2
  • Django 1.10

Djangoをインストール

Pythonのパッケージ管理システムであるpipを用いて導入する。
Python 3.4以降のバージョンにはデフォルトでインストールされているが
未インストールの場合はインスコしてください。

pipでDjangoをインストールする。
$ pip install django==1.10

$ pip list
でDjangoが表示されていればインストール完了。

Djangoを動かしてみる

プロジェクトの作成

まずはプロジェクトを作成する。
$ django-admin startproject testProject

コマンドを実行したディレクトリに、testProject というディレクトリができる。

サーバーを起動する

testProjectディレクトリに移動する。
$ cd testProject

サーバーを起動する。
引数に、ipアドレスとポート番号を指定する。
引数を指定しない場合、127.0.0.1の8000番が指定される。

$ python manage.py runserver [ipアドレス:ポート番号]

Performing system checks...

System check identified no issues (0 silenced).

You have 13 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.

April 01, 2017 - 12:43:16
Django version 1.10, using settings 'firstDjango.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.

デフォルトの場合はhttp://127.0.0.1:8000/
にアクセスし、以下の画面が表示されればサーバーの起動に成功している。

djangotest.PNG

アクセスできない場合は、IPアドレスの設定を確認する。

CTRL + C でサーバーを終了。

サーバー起動時にコマンドラインに表示される
You have 13 unapplied... というmigrationsに関するエラーを消すには
サーバーを終了してから
$ python manage.py migrate
で消すことができる。

以上、導入からテストサーバーの起動まで。

21
33
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
21
33