データベースと
サーバの起動
データベース
ウェブサービスを制作する時に欠かせないのが、データベースである。djangoも標準でデータベースを利用出来るようになっている。
- セッティング
djangoでの標準はSQlite3であるが、他のデータベースでの利用も可能である。データベースの設定は mycar/settings.pyに記述されている。12345678910111213...# Build paths inside the project like this: os.path.join(BASE_DIR, ...)BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))...# Database# https://docs.djangoproject.com/en/1.9/ref/settings/#databasesDATABASES = {'default': {'ENGINE': 'django.db.backends.sqlite3','NAME': os.path.join(BASE_DIR, 'db.sqlite3'),}} - マイグレーション
以下の操作により、データベースのマイグレーションをおこなう1234567891011121314151617(env1)$ python manage.py migrateOperations to perform:Apply all migrations: sessions, admin, contenttypes, authRunning migrations:Rendering model states... DONEApplying contenttypes.0001_initial... OKApplying auth.0001_initial... OKApplying admin.0001_initial... OKApplying admin.0002_logentry_remove_auto_add... OKApplying contenttypes.0002_remove_content_type_name... OKApplying auth.0002_alter_permission_name_max_length... OKApplying auth.0003_alter_user_email_max_length... OKApplying auth.0004_alter_user_username_opts... OKApplying auth.0005_alter_user_last_login_null... OKApplying auth.0006_require_contenttypes_0002... OKApplying auth.0007_alter_validators_add_error_messages... OKApplying sessions.0001_initial... OK - スーパーユーザの作成
123456(env1)$ python manage.py createsuperuserUsername (leave blank to use 'hoge'): adminEmail address: admin@example.comPassword: hogefugaPassword (again): hogefugaSuperuser created successfully.
開発用サーバの起動
今回の開発はLAN内で開発用のサーバとクライアントを分けているので、注意する事!
1 |
(env1)$ python manage.py runserver 0.0.0.0:8000 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
(env1) ooo@teamheaven:~/python/PycharmProjects/mycar$ python manage.py runserver 0.0.0.0:8000 Performing system checks... System check identified no issues (0 silenced). January 03, 2017 - 04:28:50 Django version 1.9.2, using settings 'mycar.settings' Starting development server at http://0.0.0.0:8000/ Quit the server with CONTROL-C. Not Found: / [03/Jan/2017 04:29:06] "GET / HTTP/1.1" 200 1942 Not Found: /favicon.ico [03/Jan/2017 04:29:07] "GET /favicon.ico HTTP/1.1" 404 1939 Not Found: /favicon.ico [03/Jan/2017 04:29:07] "GET /favicon.ico HTTP/1.1" 404 1939 |