Day#4 프로젝트 환경 세팅 시작

정은경·2020년 3월 4일
0
post-thumbnail

개념적/논리적 스키마 수정하기

오후 10시에 스크럼 회의때 오늘 한일을 말할 수 있어야 해서
부랴부랴 개념적/논리적 스키마를 수정하였다.
매일 scrum 회의를 하는 건 프로젝트의 적당한 긴장감을 주어서 좋은 것 같다!

오후 10시 2번째 원격 scrum 회의

디자인/프론트엔드/백엔드
각자 done/blocking-poing/to-do에 대해서 의논하는 시간

오늘의 to-do는 프로젝트 환경 세팅!

1. conda 가상환경 만들기

conda create -n petsmara python=3.7
conda activate petsmara

2. django 설치하기

pip install django

3. 프로젝트에 필요한 라이브러리 설치하기

pip install django-cors-headers
pip install bcrypt
pip install pyjwt
pip install mysqlclient
(petsmara) marie@MarieJungui-MacBookPro:~ » pip freeze
asgiref==3.2.3
bcrypt==3.1.7
certifi==2019.11.28
cffi==1.14.0
Django==3.0.4
django-cors-headers==3.2.1
mysqlclient==1.4.6
pycparser==2.20
PyJWT==1.7.1
pytz==2019.3
six==1.14.0
sqlparse==0.3.1
(petsmara) marie@MarieJungui-MacBookPro:~ »

4. 프로젝트 폴더 생성하고 장고 실행하기

(petsmara) marie@MarieJungui-MacBookPro:~ » mkdir petsmara_backend
(petsmara) marie@MarieJungui-MacBookPro:~ » cd petsmara_backend
(petsmara) marie@MarieJungui-MacBookPro:~/petsmara_backend »
(petsmara) marie@MarieJungui-MacBookPro:~/petsmara_backend » django-admin startproject django_admin
(petsmara) marie@MarieJungui-MacBookPro:~/petsmara_backend » ls -al
total 0
drwxr-xr-x   3 marie  staff    96  3  5 00:27 .
drwxr-xr-x+ 78 marie  staff  2496  3  5 00:27 ..
drwxr-xr-x   4 marie  staff   128  3  5 00:27 django_admin
(petsmara) marie@MarieJungui-MacBookPro:~/petsmara_backend » cd django_admin
(petsmara) marie@MarieJungui-MacBookPro:~/petsmara_backend/django_admin »
(petsmara) marie@MarieJungui-MacBookPro:~/petsmara_backend/django_admin »       1 ↵
(petsmara) marie@MarieJungui-MacBookPro:~/petsmara_backend/django_admin » tree                     1 ↵
.
├── db.sqlite3
├── django_admin
│   ├── __init__.py
│   ├── __pycache__
│   │   ├── __init__.cpython-37.pyc
│   │   ├── settings.cpython-37.pyc
│   │   └── urls.cpython-37.pyc
│   ├── asgi.py
│   ├── settings.py
│   ├── urls.py
│   └── wsgi.py
└── manage.py

2 directories, 10 files
(petsmara) marie@MarieJungui-MacBookPro:~/petsmara_backend/django_admin »
(petsmara) marie@MarieJungui-MacBookPro:~/petsmara_backend/django_admin » 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 admin.0003_logentry_add_action_flag_choices... 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 auth.0009_alter_user_last_name_max_length... OK
  Applying auth.0010_alter_group_name_max_length... OK
  Applying auth.0011_update_proxy_permissions... OK
  Applying sessions.0001_initial... OK
(petsmara) marie@MarieJungui-MacBookPro:~/petsmara_backend/django_admin »
(petsmara) marie@MarieJungui-MacBookPro:~/petsmara_backend/django_admin » python manage.py createsuperuser
Username (leave blank to use 'marie'): petsmara
Email address: petsmara2020@gmail.com
Password:
Password (again):
Superuser created successfully.
(petsmara) marie@MarieJungui-MacBookPro:~/petsmara_backend/django_admin »
(petsmara) marie@MarieJungui-MacBookPro:~/petsmara_backend/django_admin »
(petsmara) marie@MarieJungui-MacBookPro:~/petsmara_backend/django_admin »
(petsmara) marie@MarieJungui-MacBookPro:~/petsmara_backend/django_admin » python manage.py runserver
Watching for file changes with StatReloader
Performing system checks...

System check identified no issues (0 silenced).
March 04, 2020 - 15:32:34
Django version 3.0.4, using settings 'django_admin.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
[04/Mar/2020 15:32:39] "GET / HTTP/1.1" 200 16351
[04/Mar/2020 15:32:39] "GET /static/admin/css/fonts.css HTTP/1.1" 200 423
Not Found: /robots.txt
[04/Mar/2020 15:32:39] "GET /robots.txt HTTP/1.1" 404 1975
[04/Mar/2020 15:32:39] "GET /static/admin/fonts/Roboto-Bold-webfont.woff HTTP/1.1" 200 86184
[04/Mar/2020 15:32:39] "GET /static/admin/fonts/Roboto-Regular-webfont.woff HTTP/1.1" 200 85876
[04/Mar/2020 15:32:39] "GET /static/admin/fonts/Roboto-Light-webfont.woff HTTP/1.1" 200 85692
Not Found: /favicon.ico
[04/Mar/2020 15:32:39] "GET /favicon.ico HTTP/1.1" 404 1978
[04/Mar/2020 15:32:52] "GET /admin HTTP/1.1" 301 0
[04/Mar/2020 15:32:52] "GET /admin/ HTTP/1.1" 302 0
[04/Mar/2020 15:32:52] "GET /admin/login/?next=/admin/ HTTP/1.1" 200 1913
[04/Mar/2020 15:32:52] "GET /static/admin/css/base.css HTTP/1.1" 200 16378
[04/Mar/2020 15:32:52] "GET /static/admin/css/login.css HTTP/1.1" 200 1233
[04/Mar/2020 15:32:52] "GET /static/admin/css/responsive.css HTTP/1.1" 200 18052
[04/Mar/2020 15:33:02] "POST /admin/login/?next=/admin/ HTTP/1.1" 200 2077
[04/Mar/2020 15:33:06] "POST /admin/login/?next=/admin/ HTTP/1.1" 302 0
[04/Mar/2020 15:33:06] "GET /admin/ HTTP/1.1" 200 3045
[04/Mar/2020 15:33:06] "GET /static/admin/css/dashboard.css HTTP/1.1" 200 412
[04/Mar/2020 15:33:06] "GET /static/admin/img/icon-addlink.svg HTTP/1.1" 200 331
[04/Mar/2020 15:33:06] "GET /static/admin/img/icon-changelink.svg HTTP/1.1" 200 380

5. requirements.txt 파일 생성하기

(petsmara) marie@MarieJungui-MacBookPro:~/petsmara_backend/petsmara » pip freeze > requirements.txt
(petsmara) marie@MarieJungui-MacBookPro:~/petsmara_backend/petsmara »
(petsmara) marie@MarieJungui-MacBookPro:~/petsmara_backend/petsmara » cat requirements.txt
asgiref==3.2.3
bcrypt==3.1.7
certifi==2019.11.28
cffi==1.14.0
Django==3.0.4
django-cors-headers==3.2.1
mysqlclient==1.4.6
pycparser==2.20
PyJWT==1.7.1
pytz==2019.3
six==1.14.0
sqlparse==0.3.1
(petsmara) marie@MarieJungui-MacBookPro:~/petsmara_backend/petsmara »

6. ".gitignore 생성하기"

https://www.gitignore.io/

(petsmara) marie@MarieJungui-MacBookPro:~/petsmara_backend/petsmara » vi .gitignore
(petsmara) marie@MarieJungui-MacBookPro:~/petsmara_backend/petsmara »

7. corsheaders 플러그인을 위한 settings.py 설정 추가

# Application definition

INSTALLED_APPS = [
   # 'django.contrib.admin',
   # 'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'corsheaders',
    'user',
    'comment',
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    #'django.middleware.csrf.CsrfViewMiddleware',
    #'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
    'corsheaders.middleware.CorsMiddleware',
]

##CORDS
CORS_ORIGIN_ALLOW_ALL = True
CORS_ALLOW_CREDENTIALS = True

CORS_ALLOW_METHODS = (
    'DELETE',
    'GET',
    'OPTIONS',
    'PATCH',
    'POST',
    'PUT',
)

CORS_ALLOW_HEADERS = (
    'accept',
    'accept-encoding',
    'authorization',
    'content-type',
    'dnt',
    'origin',
    'user-agent',
    'x-csrftoken',
    'x-requested-with',
)

8. url 설계를 위한 settings.py 설정 추가

##Disable_slash
APPEND_SLASH = False

9. settings.py의 시크릿키를 외부에서 가지고 오도록 설정

import os
import my_settings

# 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/3.0/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = my_settings.SECRET_KEY

10. 장고 한국 시간으로 변경하기

Reference

profile
#의식의흐름 #순간순간 #생각의스냅샷

0개의 댓글