(pyenv) [test@SAKURA_VPS pyenv]$ pwd /home/test/pyenv
(pyenv) [test@SAKURA_VPS pyenv]$ django-admin startproject todo ← todoプロジェクトを作成します。
(pyenv) [test@SAKURA_VPS pyenv]$ cd todo/
(pyenv) [test@SAKURA_VPS todo]$ python manage.py startapp todo_app ← Web アプリを作成します。
(pyenv) [test@SAKURA_VPS todo]$ python manage.py migrate ← マイグレーションします。 Operations to perform: Apply all migrations: admin, auth, contenttypes, sessions Running migrations:
Applying contenttypes.0001_initial… OK
Applying auth.0001_initial… OK
Applying admin.0001_initial… OK
Applying admin.0002_logentry_remove_auto_add… OK
Applying contenttypes.0002_remove_content_type_name… OK
Applying auth.0002_alter_permission_name_max_length… OK
Applying auth.0003_alter_user_email_max_length… OK
Applying auth.0004_alter_user_username_opts… OK
Applying auth.0005_alter_user_last_login_null… OK
Applying auth.0006_require_contenttypes_0002… OK
Applying auth.0007_alter_validators_add_error_messages… OK
Applying auth.0008_alter_user_username_max_length… OK
Applying sessions.0001_initial… OK
(pyenv) [test@SAKURA_VPS todo]$
settings.pyファイルを編集する
settings.pyファイルを編集します。
何のために編集するかと言うと
アプリケーション(todo_app)の登録
日本語環境の設定
タイムゾーンの設定
style.cssや画像ファイルの場所設定
をしています。
(pyenv) [test@SAKURA_VPS todo]$ pwd /home/test/pyenv/todo/todo
(pyenv) [test@SAKURA_VPS todo]$ vi settings.py “”” Django settings for todo project.
Generated by ‘django-admin startproject’ using Django 1.11.7.
For more information on this file, see https://docs.djangoproject.com/en/1.11/topics/settings/
For the full list of settings and their values, see https://docs.djangoproject.com/en/1.11/ref/settings/ “””
import os
# Build paths inside the project like this: os.path.join(BASE_DIR, …)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Quick-start development settings – unsuitable for production
# See https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = ‘9@)yi&kb6xxxxxxxxxxxxxxxxxxxxxxxm99&oq’
# SECURITY WARNING: don’t run with debug turned on in production!
DEBUG = True
The `urlpatterns` list routes URLs to views. For more information please see: https://docs.djangoproject.com/en/1.11/topics/http/urls/ Examples: Function views 1. Add an import: from my_app import views 2. Add a URL to urlpatterns: url(r’^$’, views.home, name=’home’) Class-based views 1. Add an import: from other_app.views import Home 2. Add a URL to urlpatterns: url(r’^$’, Home.as_view(), name=’home’) Including another URLconf 1. Import the include() function: from django.conf.urls import url, include 2. Add a URL to urlpatterns: url(r’^blog/’, include(‘blog.urls’)) “””
from django.conf.urls import include,url
from django.contrib import admin
(pyenv) [test@SAKURA_VPS todo_app]$ vi result.html {% block body %} {% if result_list %} {% for i in result_list %} <p><input type=”checkbox” name=”delete_text” value=”{{i.id}}”>{{i.new_message}}:{{i.created_at}}</p>
(pyenv) [test@SAKURA_VPS todo]$ python manage.py runserver
Performing system checks…
System check identified no issues (0 silenced).
November 11, 2017 – 20:23:27
Django version 1.11.7, using settings ‘todo.settings’
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
[12/Nov/2017 09:13:54] “GET /todo_app HTTP/1.1” 200 175
Traceback (most recent call last):
File “/usr/lib64/python3.6/wsgiref/handlers.py”, line 137, in run
self.result = application(self.environ, self.start_response)
File “/home/test/pyenv/lib64/python3.6/site-packages/django/contrib/staticfiles/handlers.py”, line 64, in __call__
return super(StaticFilesHandler, self).__call__(environ, start_response)
File “/home/test/pyenv/lib64/python3.6/site-packages/django/core/handlers/wsgi.py”, line 157, in __call__
response = self.get_response(request)
File “/home/test/pyenv/lib64/python3.6/site-packages/django/contrib/staticfiles/handlers.py”, line 54, in get_response
return self.serve(request)
File “/home/test/pyenv/lib64/python3.6/site-packages/django/contrib/staticfiles/handlers.py”, line 47, in serve
return serve(request, self.file_path(request.path), insecure=True)
File “/home/test/pyenv/lib64/python3.6/site-packages/django/contrib/staticfiles/views.py”, line 34, in serve
absolute_path = finders.find(normalized_path)
File “/home/test/pyenv/lib64/python3.6/site-packages/django/contrib/staticfiles/finders.py”, line 249, in find
for finder in get_finders():
File “/home/test/pyenv/lib64/python3.6/site-packages/django/contrib/staticfiles/finders.py”, line 264, in get_finders
yield get_finder(finder_path)
File “/home/test/pyenv/lib64/python3.6/site-packages/django/contrib/staticfiles/finders.py”, line 277, in get_finder
return Finder()
File “/home/test/pyenv/lib64/python3.6/site-packages/django/contrib/staticfiles/finders.py”, line 57, in __init__ “Your STATICFILES_DIRS setting is not a tuple or list; “
django.core.exceptions.ImproperlyConfigured: Your STATICFILES_DIRS setting is not a tuple or list; perhaps you forgot a trailing comma?
[12/Nov/2017 09:13:55] “GET /static/css/style.css HTTP/1.1” 500 59
以下を修正しました。
【修正前】
(pyenv) [test@SAKURA_VPS todo]$ pwd /home/test/pyenv/todo/todo
(pyenv) [test@SAKURA_VPS todo]$ vi settings.py
System check identified no issues (0 silenced).
November 12, 2017 – 10:00:22
Django version 1.11.7, using settings ‘todo.settings’
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
[12/Nov/2017 10:00:31] “GET /todo_app HTTP/1.1” 200 175 [12/Nov/2017 10:00:31] “GET /static/css/style.css HTTP/1.1” 404 1652
^C(pyenv) [test@SAKURA_VPS todo]$ ← 「Ctrl」+「C」で一旦開発サーバーを停止します。
(pyenv) [test@SAKURA_VPS todo]$
(pyenv) [test@SAKURA_VPS todo]$ python manage.py migrate
Operations to perform:
Apply all migrations: admin, auth, contenttypes, sessions
Running migrations: No migrations to apply. Your models have changes that are not yet reflected in a migration, and so won’t be applied. Run ‘manage.py makemigrations’ to make new migrations, and then re-run ‘manage.py migrate’ to apply them. ← モデルを変更した場合は、初めに「makemigrations」を実行するように言われました。
(pyenv) [test@SAKURA_VPS todo]$ python manage.py makemigrations
Migrations for ‘todo_app’:
todo_app/migrations/0001_initial.py
– Create model Todo_board
(pyenv) [test@SAKURA_VPS todo]$ python manage.py migrate
Operations to perform:
Apply all migrations: admin, auth, contenttypes, sessions, todo_app
Running migrations:
Applying todo_app.0001_initial… OK
(pyenv) [test@SAKURA_VPS todo]$ python manage.py runserver
Performing system checks…
System check identified no issues (0 silenced).
November 12, 2017 – 10:25:48
Django version 1.11.7, using settings ‘todo.settings’
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
[12/Nov/2017 10:25:54] “GET /todo_app HTTP/1.1” 200 175
[12/Nov/2017 10:26:02] “GET /todo_app HTTP/1.1” 200 175 [12/Nov/2017 10:26:02] “GET /static/css/style.css HTTP/1.1” 200 64← ゲットは出来ているようです。
コメント