DRF(Django Rest Framework) and Vue.js

Likelion 7th
python -m venv venv(powershell, venv 기준 가상환경 activate다.)
cd venv/Scripts/
source venv/Scripts/activate
pip install djangopython startproject spacd spapython startapp user
project, app 만든 이후 파일 구조, splite3는 차후 설명하겠음
spa/settings.py# installed app에 다음과 같은 내용들이 추가된다.
#밑의 pip install을 통째로 복붙한다.
# pip install django-rest-auth django-allauth django-rest-framework django-cors-headers djangorestframework-jwt
#pip list를 했을 때 추가되는 것들
django-allauth 0.39.1
django-cors-headers 3.0.2
django-rest-auth 0.9.5
django-rest-framework 0.1.0
djangorestframework 3.10.2
djangorestframework-jwt 1.11.0
spa/settings.pyMIDDLEWARE = [# 절대 잊지 말자!! middleware 최상단에 corsheaders를 위치시키자.'corsheaders.middleware.CorsMiddleware',...]
# spa/settings.py# cors header settingCORS_ORIGIN_ALLOW_ALL = FalseCORS_ORIGIN_WHITELIST = [""
CORS_ALLOW_METHODS = ('DELETE','GET','OPTIONS','PATCH','POST','PUT',)CORS_ALLOW_HEADERS = ('accept','accept-encoding','authorization','access-control-request-method','access-control-request-headers','content-type','dnt','origin','user-agent','x-csrftoken','x-requested-with',)
AUTH_USER_MODEL = "app이름.앱에 있는 유저 모델 class 이름"SITE_ID = 1REST_FRAMEWORK = {'DEFAULT_AUTHENTICATION_CLASSES': ('rest_framework.authentication.TokenAuthentication','rest_framework.authentication.SessionAuthentication','rest_framework_jwt.authentication.JSONWebTokenAuthentication',),'DEFAULT_PERMISSION_CLASSES': ('rest_framework.permissions.IsAuthenticated',),}#JWT_AUTH 설정을 위해 settings.py 맨 위해 import datetime을 추가하자!!JWT_AUTH = {# If the secret is wrong, it will raise a jwt.DecodeError telling you as such. You can still get at the payload by setting the JWT_VERIFY to False.'JWT_VERIFY': True,# You can turn off expiration time verification by setting JWT_VERIFY_EXPIRATION to False.# If set to False, JWTs will last forever meaning a leaked token could be used by an attacker indefinitely.'JWT_VERIFY_EXPIRATION': True,# This is an instance of Python's datetime.timedelta. This will be added to datetime.utcnow() to set the expiration time.# Default is datetime.timedelta(seconds=300)(5 minutes).'JWT_EXPIRATION_DELTA': datetime.timedelta(hours=1),'JWT_ALLOW_REFRESH': True,'JWT_AUTH_HEADER_PREFIX': 'JWT',}REST_USE_JWT = True
(Bash)python manage.py makemigrationspython manage.py migratepython manage.py createsuperuser




Software Engineer

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Ryan Kim

Ryan Kim

Software Engineer

More from Medium

Dockerizing Vue App With NodeJS Backend — Typescript Version

Tutorial for Docker on Windows

Connect MongoDB Docker Container With Robo 3T and Mongo Express

A Container illustration from Docker

How to install and Secure Redis on Ubuntu 22.04