๐ Django Project
๐ญ ํ๋ก์ ํธ ๋ฐํ ์งํ
KPT ํ๊ณ
๐ญ ํ๋ก์ ํธ ๋ฆฌํฉํ ๋ง
- ํ๋ก์ ํธ์ ์๋จ ์ฅ๋ฅด ์นดํ
๊ณ ๋ฆฌ๋ฐ๋ฅผ ์ ๋ ์งํํ์ ๋
POST
๋ฐฉ์์ผ๋ก ๊ฐ์ ๋ฐ์์ ๋ฐฑ์ค๋๋ก ์ด์ฃผ๋ ๋ฐฉ์์ผ๋ก ๋ง๋ค์์๋ค. ์ด๊ฒ์ GET
๋ฐฉ์์ผ๋ก ๋ค์ ๋ฆฌํฉํ ๋งํด๋ณด์๋ค.
- ์ค์ ๋ก
GET
์ผ๋ก ํ๋ a ๋งํฌ
๋ง์ผ๋ก๋ ํ๋ก ํธ ํ์ด์ง๋ฅผ ๊ตฌ์ฑํ ์ ์์๋ค.
- ๋ํ 19๊ฐ์ ์ฅ๋ฅด๋ฅผ ํ๋์ฝ๋ฉ์ด ์๋
for ๋ฌธ
์ ํ์ฉํด ๊น๋ํ๊ฒ ํํํด ์ฃผ์๋ค. ์ฌ๊ธฐ์ for ๋ฌธ ์์ ์ฐ์ด๋ ๊ฐ์ ๋ฐฑ์ค๋์์ ํ ๋ฒ ๋ ๋ณด๋ด์ฃผ์ด์ผ ์๋จ์ ์นดํ
๊ณ ๋ฆฌ๊ฐ ์ฌ๋ผ์ง์ง ์๊ณ ๊ณ์ ์กด์ฌํ๋ ๊ฒ์ ์ ์ ์๋ค.
movie/views.py
def tagging(request, name):
if request.method == 'GET':
tag_all = Tag.objects.all()
tag = Tag.objects.get(tag=name)
max_score = tag.movies.filter(tag=tag.id)
return render(request, 'movie/home.html', {'movies': max_score,'tag_all': tag_all, 'tag': tag})
from django.urls import path
from movie import views
urlpatterns = [
path('', views.home, name='home'),
path('detail/<int:id>/', views.detail, name='detail'),
path('search/', views.search, name='search'),
path('tag/<str:name>/', views.tagging, name='tagging'),
]
{% block content %}
<ul class="nav nav-tabs">
<li class="nav-item">
<a class="nav-link active" id="all" href="http://127.0.0.1:8000/">All</a>
</li>
{% for tag in tag_all %}
<li class="nav-item">
<a class="nav-link" id="{{ tag.id }}" href="/tag/{{ tag }}/">{{ tag }}</a>
</li>
{% endfor %}
</ul>
{% endblock %}
{% block script %}
var aTags = document.getElementById('{{ tag.id }}')
var tag = aTags.innerText
var all = document.getElementById('all')
var searchText = "{{ tag }}";
if (tag == searchText) {
aTags.classList.toggle('active')
all.classList.toggle('active')
} else {
all.classList.toggle('active')
}
{% endblock %}