makeBCT

#AI #OpenAI #Chatbot #Cloud #WordPress

Building a Django Web App – Django III > User-submitted content

Django III에서 다루게 될 내용은 다음과 같습니다.

4-1 Django custom user profile

4-2 User-submitted content

4-3 Finishing touches


4-2 User-submitted content

(1) Creating a vote model

Vote model을 models.py에 추가

다음과 같이 코드를 추가합니다.

mysite > main > models.py

 

Migrations 수행

다음 명령을 수행합니다.

>python manage.py makemigrations
>python manage.py migrate

 

Vote model을 폼에 연결

다음과 같이 코드를 추가합니다.

mysite > main > forms.py

 

VoteForm을 product 함수에 추가

다음과 같이 코드를 추가합니다.

mysite > main > views.py

 

(2) Adding the vote form to the products page

Bootstrap collapse를 product.html에 추가

다음과 같이 코드를 추가합니다.

mysite > main > templates > main > products.html

 

script를 product.html에 추가

다음과 같이 코드를 추가합니다.

mysite > main > templates > main > products.html

 

style를 products.html에 추가

 

브라우저에서 확인해 봅니다.

 

(3) Handling the vote form submission

views.py에 product 기능 업데이트

다음과 같이 코드를 추가합니다.

mysite > main > views.py

 

브라우저에서 확인해 봅니다.

 

(4) Displaying the product scores

models.py에 Product model 업데이트

다음과 같이 코드를 추가합니다.

mysite > main > models.py

 

Function을 Vote 모델에 추가

다음과 같이 코드를 추가합니다.

mysite > main > models.py

 

Migrations 수행

다음 명령을 수행합니다.

>python manage.py makemigrations
>python manage.py migrate

 

views.py에 products view 업데이트

다음과 같이 코드를 추가합니다.

mysite > main > views.py

 

products.html에서 products에 user score 추가

다음과 같이 코드를 추가합니다.

mysite > main > views.py

 

home.html에서 products에 user score 추가

mysite > main > templates > main > home.html

 

브라우저에서 확인해 봅니다.

 

브라우저에서 확인해 봅니다.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

인기 글

사용자 작성 모듈 import 시 에러)(ModuleNotFoundError: No module named
파이썬 모듈을 만들고 테스트 할 때 ModuleNotFoundError: No module named 에러가 발생한 경우원인파이썬은 모듈을 불러올 때 모듈 설치 경로와 자신의...
오라클 클라우드 OCI 가입 드디어 성공 했습니다 (상세 후기)
2023년 2월 16일에 ‘오라클 클라우드 지급 검증 실패 글‘을 남긴 적이 있습니다.그 때 검색을 통해 해결 방법을 찾아 보았고, 당시 성공했던 분들의...
AWS 인스턴스 유형 변경 방법
AWS 인스턴스 유형을 변경하기 위한 방법에는 다음 2가지가 있습니다.   1. 첫 번째 방법 AMI 이미지 생성 후 해당 이미지를 복원하여 신규 EC2 인스턴스를 생성하는...
Ubuntu 22.04 LTS에 Python 3.8 or 3.9 설치 방법
서버 : Vultr 클라우드OS: Ubuntu 22.04 LTS사용자 계정 생성하여 설치 진행함1. Start with the system updatesudo apt update...
Ubuntu 20.04에 MySQL 5.7 설치
비씨티원 인공지능 서비스 플랫폼 BAP(Bctone AI service Platform)의 설치 환경은 공식적으로 Ubuntu 18.04와 MySQL 버전 5.7 입니다. 최근 Ubuntu...

BCT Ai Chatbot

답변을 준비중입니다 . . .