- Django Rest Framework
Front JS CRUD
[js에서 변수 불러오기]
js에서 변수를 불러올때 변수 앞 뒤로 내가 원하는 문구를 넣고 싶을때가 있다.
이럴땐 정말 간단하게 불러오는 변수 앞 뒤로 "문자열"을 +(추가) 해주면 된다.
async function user_mbti() {
const response = await fetch(`${main_url}/users/signup/${userId}/userchr/`, {
headers: {
'Authorization': 'Bearer ' + localStorage.getItem('access'),
'content-type': 'application/json',
},
method: 'GET'
})
response_json = await response.json()
const user_mbti = document.getElementById('input_mbti')
user_mbti.setAttribute("value", "내 MBTI는 "+response_json.mbti)
}
위의 코드를 살펴보면 user_mbti에 백엔드에서 가져온 정보 중 mbti를 넣게 되는데 가져오는 mbti 앞에 문구를 넣기위해 "내 MBTI는" +
을 추가해줘서 표현했다.
'woncoding > TIL' 카테고리의 다른 글
| TIL | 12.23.금 [사용자 피드백] (0) | 2022.12.25 |
|---|---|
| TIL | 12.22.목 [DRF ↔️ JS CRUD] (0) | 2022.12.25 |
| TIL | 12.20.화 [DRF ↔️ JS CRUD] (0) | 2022.12.23 |
| TIL | 12.19.월 [Docker | nginx + postgresql + django] (0) | 2022.12.19 |
| TIL | 12.16.금 [Docker | nginx / postgresql / django] (0) | 2022.12.19 |