-
django show-list by FBVProject using python/Cloning Airbnb 2021. 4. 23. 14:35
url 설정
config/urls.py
urlpatterns = [ path("lists/", include("lists.urls", namespace="lists")) ]
lists/urls.py
from django.urls import path from lists import views app_name = "lists" urlpatterns = [ path("favs/", views.favs, name="favs"), ]
Client
pages/lists/fav_list.html
{% extends 'base.html' %} {% block page_title %} Favs {% endblock page_title %} {% block content %} <div class="flex flex-col items-center justify-items-center"> <div class="w-10/12"> {% include 'mixins/room_card.html' with rooms=rooms %} <div class="flex justify-center mt-20 itmes-center"> {% include 'mixins/page_number.html' with page=rooms %} </div> </div> </div> {% endblock content %}
FBV(Function Based View)
lists/views.py
# lists/views.py from django.shortcuts import redirect, reverse, render from django.core.pagiantor import Paginator from django.contrib import messages from lists import models as list_models def favs(request): page = request.GET.get("page", 1) if page == "": page = 1 else: page = int(page) page_sector = ((page - 1) // 5) * 5 the_list = list_models.List.objects.get_or_none(user=request.user) if the_list is None: messages.error(request, "List does not exist") return redirect(reverse("core:home")) qs = the_list.rooms.all() paginator = Paginator(qs, 12, orphans=6) rooms = paginator.get_page(page) return render( request, "pages/lists/list_detail.html", context={"rooms": rooms, "page_sector": page_sector}, )
참고 자료
- 노마드 코더의 Airbnb 클론 강의
소스 코드
github.com/zpskek/airbnb-clone-v3/commit/ac1cd3cff77668c5cf74f3371a5a2c97ba1d94c5
'Project using python > Cloning Airbnb' 카테고리의 다른 글
django conversations-detail by FBV (0) 2021.04.23 django create-conversation by FBV (0) 2021.04.23 django toggle-list by FBV (0) 2021.04.23 django delete-review by FBV with axios (0) 2021.03.18 django update-review with axios (0) 2021.03.18