AI 웹 개발 과정/팀 프로젝트

팀 프로젝트 04 : 추천 시스템 페이지 - 4일차 / urls.py / views.py / UI 구성

만 기 2022. 6. 9. 09:29

 

1. beer/urls.py 와 프로젝트 urls.py 연결

 

- 프로젝트 폴더 urls.py

from django.contrib import admin
from django.urls import path, include

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', include('recommend.urls')),
    path('', include('history.urls')),
    path('', include('beer.urls')),
    path('', include('user.urls')),
]
  • admin 페이지 연결
  • 해당 앱.urls 와 연결

- beer 앱의 urls.py

from django.urls import path
from . import views

urlpatterns = [
    path('rating/', views.rating, name='rating'),
]

 

 

2. beer/views.py 작성 : .order_by('-rating')

from django.shortcuts import render, redirect
from .models import Beer


def rating(request):
    if request.method == 'GET':
        beers = Beer.objects.order_by('-rating')
    return render(request, 'beer/rating.html', {'beers': beers})
  • urls.py의 url 경로를 통해서 rating 함수 실행됨
  • GET 요청시 
  • Beer 모델에서 rating 열의 값이 큰 순서대로 beers에 저장
  • response 로 beers에 담긴 데이터와 rating.html 전달

 

 

3. html, css 작성 

 

{% extends 'base.html' %}
{% load static %}

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">

    <!-- 참조할 css, js -->
    {% block link %}
        <link rel="stylesheet" href="{% static 'css/rating.css' %}">
        <script defer src="{% static 'js/rating.js' %}"></script>
    {% endblock link %}

    <!-- 페이지별 타이틀 -->
    {% block title %}
        <title>MyLittleBeer</title>
    {% endblock title %}

</head>
<body>
{% block content %}

{% endblock content %}
</body>
</html>

 

 

 

 

 

 

참조 사용

 

https://query.tistory.com/entry/%EC%9E%A5%EA%B3%A0-%EC%88%AB%EC%9E%90-%EB%B0%98%EC%98%AC%EB%A6%BC-%ED%85%9C%ED%94%8C%EB%A6%BF-%ED%95%84%ED%84%B0-floatformat

 

[장고] 숫자 반올림 - 템플릿 필터: floatformat

장고에서 숫자와 관련된 작업을 하다 보면 반올림을 해야 할 때가 있습니다. views.py에서 사용할 수 있는 파이썬(python)의 반올림 round 함수 말고, 장고에 기본적으로 내장돼 있는 필터로써, 장고

query.tistory.com

 

https://itinerant.tistory.com/13

 

[Python][Django] Template Tag < For >

For 1.일반 For문 1. 일반 For 문 {% for key in list %} {{ key }} {% endfor %} 2.For문 반전 ( Dictionary 불가능 ) 2. 반전된 For 문 {% for key in list reversed %} {{ key }} {% endfor %} 3.이중 리스트..

itinerant.tistory.com

 

https://www.w3schools.com/jsref/prop_style_overflowy.asp

 

HTML DOM Style overflowY Property

W3Schools offers free online tutorials, references and exercises in all the major languages of the web. Covering popular subjects like HTML, CSS, JavaScript, Python, SQL, Java, and many, many more.

www.w3schools.com

 

https://m.blog.naver.com/PostView.nhn?blogId=nemesis5198&logNo=221380180121&proxyReferer=https:%2F%2Fwww.google.com%2F 

 

jquery 요소밖 영역 클릭시 창이 닫히는 이벤트

윈도우 창 아무곳이나 눌러도 창이 닫히는 이벤트를 일전에 블로깅했습니다.http://nemesis5198.blog.me/22...

blog.naver.com

 

https://qjadud22.tistory.com/7

 

[Jquery] 현재 위치에서 팝업창 가운데로 띄우기(뒷배경 불투명)

스크롤 바를 내린 상태에서 팝업 창을 띄우면 상단에 팝업창이 생기는 문제가 발생할 수 있다. "top": (($(window).height()-$("#popupDiv").outerHeight())/2+$(window).scrollTop())+"px" "left": (($(win..

qjadud22.tistory.com

 

http://daplus.net/javascript-%EC%9E%A5%EA%B3%A0-%ED%85%9C%ED%94%8C%EB%A6%BF-%EB%B3%80%EC%88%98%EC%99%80-%EC%9E%90%EB%B0%94-%EC%8A%A4%ED%81%AC%EB%A6%BD%ED%8A%B8/

 

[javascript] 장고 템플릿 변수와 자바 스크립트 - 리뷰나라

Django 템플릿 렌더러를 사용하여 페이지를 렌더링 할 때 다양한 값을 포함하는 사전 변수를 전달하여을 사용하여 페이지에서 해당 값을 조작 할 수 있습니다 {{ myVar }}. Javascript에서 동일한 변수

daplus.net

 

https://iamiet.tistory.com/21

 

[Django] Static 태그 내에서 변수를 사용하는 방법

● 증상 위 코드처럼 DTL 태그를 사용하여 이미지를 불러오는 코드를 작성했다. 하지만 화면에서 사진이 깨지는것으로 보여 개발자도구를 확인하니 아래처럼 출력되었다. ● 해결방법 위 처럼 {{

iamiet.tistory.com

 

https://cholol.tistory.com/552

 

Django:제로부터 시작하는 인스타그램 만들기 - clone instagram #4

2021.09.15 - [Study/python] - Django:제로부터 시작하는 인스타그램 만들기 - clone instagram 목차 피드 업로드를 위한 모달 만들기 이번 포스팅에서는 피드를 업로드하는 화면을 만들어보겠습니다. 실제 인

cholol.tistory.com

 

https://ming9mon.tistory.com/80

 

부트스트랩 Modal창 사용법

부트스트랩 Modal창을 이용하기 위해서는 부트스트랩의 css와 jQuery를 등록시켜 주어야 된다. 등록시킨 뒤 페이지에 Modal 소스를 넣어주고 스크립트로 보여주면 된다. Modal example <!DOCTYPE html> 모달

ming9mon.tistory.com

 

https://medium.com/@antoinewg/simple-modal-to-open-details-of-an-item-django-bootstrap-ffeeb11f12c1

 

Simple modal to open details of an item (Django + bootstrap)

Here’s a simple explanation and implementation.

medium.com