drf ๋ฐฑ์๋๊ฐ๋ฐ + ํ๋ก ํธ๊ฐ๋ฐ
: ์ด๋ฒ ํ๋ก์ ํธ๋ ํํ๋ก์ ํธ๋ก ์์ํฉ๋๋ค.
views.py
# ๊ฒ์ํ๋ณ ์ํฐํด ๋ฆฌ์คํ
class ArticleByBoard(APIView):
def get(self, request):
boards = request.query_params.getlist('boards', '')
print(boards)
results = []
for board in boards:
articles = ArticleModel.objects.filter(board__name=board).order_by("-id")[:5]
result = ArticleSerializer(articles, many=True).data
results_data = {
f"{board}" : result
}
results.append(results_data)
return Response(results)
main.js
// ๊ฒ์ํ๋ณ ๊ฒ์๊ธ ๋ฆฌ์คํ
myData().then((data) => {
detail = response_json
console.log(detail)
try {
for (let i = 0; i < 5; i++) {
let title = detail[0]['์ง์ฅ์ธ'][i]['article_title']
let id = detail[0]['์ง์ฅ์ธ'][i]['id']
let temp_html = `
<div class="board-title" id="worker"token interpolation">${frontend_base_url}/detail.html?id=${id}'">${title}
</div>`
$('#company-box').prepend(temp_html)
}} catch (err) {
}
try{
for (let i = 0; i < 5; i++) {
let title = detail[1]['๋ํ์'][i]['article_title']
let id = detail[1]['๋ํ์'][i]['id']
let temp_html = `
<div class="board-title" id="worker"token interpolation">${frontend_base_url}/detail.html?id=${id}'">${title}
</div>`
$('#college-box').prepend(temp_html)
}} catch (err) {}
try{
for (let i = 0; i < 5; i++) {
let title = detail[2]['10๋'][i]['article_title']
let id = detail[2]['10๋'][i]['id']
let temp_html = `
<div class="board-title" id="worker"token interpolation">${frontend_base_url}/detail.html?id=${id}'">${title}
</div>`
$('#teen-box').prepend(temp_html)
}} catch (err) {}
try{
for (let i = 0; i < 5; i++) {
let title = detail[3]['LGBTQ'][i]['article_title']
let id = detail[3]['LGBTQ'][i]['id']
let temp_html = `
<div class="board-title" id="worker"token interpolation">${frontend_base_url}/detail.html?id=${id}'">${title}
</div>`
$('#lgbtq-box').prepend(temp_html)
}} catch (err) {}
try {
for (let i = 0; i < 5; i++) {
let title = detail[4]['์์ '][i]['article_title']
let id = detail[4]['์์ '][i]['id']
let temp_html = `
<div class="board-title" id="worker"token interpolation">${frontend_base_url}/detail.html?id=${id}'">${title}
</div>`
$('#free-box').prepend(temp_html)
}} catch (err) {}
try {
for (let i = 0; i < 5; i++) {
let title = detail[5]['HOT'][i]['article_title']
let id = detail[5]['HOT'][i]['id']
let temp_html = `
<div class="board-title" id="worker"token interpolation">${frontend_base_url}/detail.html?id=${id}'">${title}
</div>`
$('#hot-box').prepend(temp_html)
}} catch (err) {}
// ๋ก๊ทธ์ธ ๋ก๊ทธ์์ ํ์๊ฐ์
๋ฒํผ ์จ๊ธฐ๊ธฐ
if (!localStorage.getItem("access")) {
let logout_button = document.getElementById("logout-button")
logout_button.style.visibility = "hidden"
}
else {
let login_button = document.getElementById("login-button")
let signup_button = document.getElementById("signup-button")
login_button.style.visibility = "hidden"
signup_button.style.visibility = "hidden"
}
const myData = async () => {
const response = await fetch(`${backend_base_url}/article/board/?boards=์ง์ฅ์ธ&boards=๋ํ์&boards=10๋&boards=LGBTQ&boards=์์ &boards=HOT`, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
},
}
)
์์ฃผ ์ ์ฑ์ฅํ๊ณ ์๊ตฌ๋ง ๋ช ์ฃผ์ฟค