https://velog.io/@he1256/Django-%EC%9E%A5%EA%B3%A0-%EC%B4%9D-%EC%A0%95%EB%A6%AC
로그인 베스트 튜토1 (세션인증), sqlite:
1. lect: https://www.youtube.com/watch?v=p4kFF-ym_8M
2. back_repo : https://github.com/will1001/ecommerce_django-rest_api
3. front_repo : https://github.com/will1001/ecommerce_react_js_frontend
로그인 베스트 튜토2 (세션인증), postgres: https://www.youtube.com/watch?v=89KrqjqPeZ0&list=PLJRGQoqpRwddrFlVEQV16D1jdol40ETyx&index=1
https://developer0809.tistory.com/98
https://velog.io/@wkdgus7113/Django-UserModel-%ED%99%95%EC%9E%A5-feat.-AbstractUser
https://docs.djangoproject.com/en/4.1/ref/contrib/auth/
https://dojang.io/mod/page/view.php?id=2470
python -m venv ${venv-name}
$ activate
(in cmd)가상환경 내에서 pip install django
로 장고 설치
장고 프레임워크 생성 (at 프로젝트 루트) : django-admin startproject ${PJ_NAME}
가상환경 활성화 상태서, 생성된 장고서버 디렉터리 직하단(manage.py가 있는)에서
python manage.py runserver
실행하여 서버 구동 => 마이그레이션 적용 전이기에 경고127.0.0.1:8000
포트로 장고 서버 구동 확인장고REST프레임워크
python 가상환경 접속 상태에서 pip install djangorestframework
로 설치
pip freeze
로 가상환경 내 패키지 및 버전 확인
python manage.py migrate
를 통해 마이그레이션 적용 : 경고 사라짐
<img src="./MD_IMG/migrated.png">
<br><br>
4. 장고서버 PJ디렉 내 `settings.py`의 `INSTALLED_APPS`에 `rest_framework` 추가
https://pgnt.tistory.com/129 따라가기 ㄱㄱ
utils, views 디렉 생성, 각각 디렉에 about.py 생성
./urls.py
from django.contrib import admin
from django.urls import path
from AAHG_server_django.views.about import get_views_about
urlpatterns = [
path('about/', get_views_about),
]
./views/about.py
#rest
from django.http import HttpResponse, JsonResponse
from django.views.decorators.csrf import csrf_exempt
from rest_framework.parsers import JSONParser
from AAHG_server_django.utils.about import get_utils_about
def get_views_about(request):
return JsonResponse(data= get_utils_about())
./utils/about.py
def get_utils_about():
return {'test': 'test'}
127.0.0.1:8000/about
요청 및 결과확인import React, { useState, useEffect } from "react";
import axios from "axios";
const About = (): JSX.Element => {
const [data, setData] = useState("");
const fetchData = async () => {
const headers = {
"Content-type": "application/json; charset=utf-8;",
Accept: "application/json",
};
axios
.get("http://127.0.0.1:8000/about/", { headers })
.then((response) => {
setData(response.data.about);
})
.catch((response) => {
alert(response.data.message);
});
};
useEffect(() => {
fetchData();
}, [setData]);
return (
<div style={{ padding: 60 }}>
<h1 style={{ fontSize: 62, fontWeight: "bold", padding: 30 }}>About</h1>
</div>
);
<div></div>;
};
export default About;
Cors 에러 해결하기
python -m pip install django-cors-header
settings.py
의 INSTALLED_APPS
에 "corsheaders"
, MIDDLEWARE
에 아래 추가"corsheaders.middleware.CorsMiddleware",
"django.middleware.common.CommonMiddleware",
settings.py에 CORS_ORIGIN_ALLOW_ALL = True
설정하여 전체 임시허용
- 정석 : https://stackoverflow.com/questions/64744518/http-localhost3000-has-been-blocked-by-cors-policy-no-access-control-allo
장고 + SQLITE 공식 튜토: https://docs.djangoproject.com/ko/4.1/intro/tutorial02/
장고 + 리액트 이커머스 앱 튜토:
- https://www.youtube.com/watch?v=RG_Y7lIDXPM
- https://github.com/justdjango/django-react-ecommerce
장고REST FW + 리액트 : https://velog.io/@minsgy/Django-RESTAPI-React-1
프로젝트 내 장고 가상환경 설정 및 장고 설치: https://tutorial.djangogirls.org/ko/django_installation/
리액트-장고 튜토:
[리액트react] 장고(Django)연동을 위한 기본 리액트 프로젝트: https://losskatsu.github.io/frontend/react-basic-setup/#%EB%B0%B1%EC%97%94%EB%93%9C
[리액트react] async 리액트에서 장고 API 요청해서 자료 받아오기(GET): https://losskatsu.github.io/frontend/react-request-api-django/#
도커 ( 리액트 + 장고 + Nginx + 마리아DB ) : https://mdntrip.tistory.com/136
도커 베스트프랙티스 ( 장고 + postgres ) :
https://www.youtube.com/watch?v=4wdNx2j1j-w
베스트 프랙티스 2 ( 장고 도커 리액트 배포 ) :
https://www.youtube.com/watch?v=e63EBEFJkH0
csrf_exempt란? : https://iamthejiheee.tistory.com/93