인기글에서는 모든게시판의 일정 추천조건을 만족한 게시글이보이는데 익명게시판에서 적은 이름은 보이지 않아야하는데 보이는 에러? 가있어서 시리얼라이저로 조건을 만들어서 보여주면 될 것 같아서 수정했다. 적용하니 바로 오류가 잡힌걸 알 수 있었다.
아래의 js에서 success empty를 해주고 아래에서 append를 해주면서 사용자가 원하는 카테고리를 눌렀을때 카테고리의 글만 보여지게끔 만들 수 있었다.
$('#blind_list').click( function() {
blind_list()
});
function blind_list() {
let category = 'blind' ;
console.log(category)
$.ajax({
type: "GET",
url: `http://127.0.0.1:8000/blind/category/?category=${category}`,
data: {},
headers: {
"Authorization": "Bearer " + localStorage.getItem("access"),
},
success: function (response) {
$('#post_list').empty()
console.log('성공:', response);
if (response.length > 0) {
for (let i = 0; i < response.length; i++) {
let id = response[i]['id']
console.log(id)
let title = response[i]['title']
let hits =response[i]['hits']
let created_at = response[i]['created_date']
let category = response[i]['category']
let user = response[i]['user']
temp_html=` <tr>
<td>${id}</td>
<td>
<onclick=q(${id})>${title}</a>
</td>
<td>${category}</td>
<td>${hits}</td>
<td>${user}</td>
<td>${created_at}</td>
</tr>`
$('#post_list').append(temp_html)
}
}
}
});
}
'TIL' 카테고리의 다른 글
drf | project | js | community | 수정권한 | payload | localstorage (0) | 2022.11.24 |
---|---|
github issue 사용, 해결 + js 새로운 배움 (0) | 2022.11.23 |
GIT | 만든 게시판앱 팀프로젝트에 pr보내고 Merge하기 (0) | 2022.11.19 |
DRF | Serializer로 익명게시판 익명처리된 data 들고오기 (0) | 2022.11.18 |
Response status에 들어가는 data의 error (0) | 2022.11.15 |