백엔드 

 

app.py

 

 
from flask import Flask, render_template, url_for, jsonify, request
from pymongo import MongoClient

app = Flask(__name__)

client = MongoClient('mongodb+srv://@cluster0..mongodb.net/?retryWrites=true&w=majority')
db = client.dbsparta

@app.route('/')
def home():
    return render_template('index.html')


@app.route('/test')
def test():
    return render_template('test.html')


@app.route('/quiz', methods=["GET"])
def quiz():
    quiz = list(db.QUIZ.find({}, {'_id': False}))
    return jsonify({'result': quiz})

@app.route('/result', methods=["GET"])
def result():
    result = list(db.RESULT.find({}, {'_id': False}))
    return jsonify({'result': result})

@app.route('/final')
def final():
    arg = request.args.get('total_score')
    return render_template('final.html', total_score=arg)
# total_score=num

@app.route('/final/score', methods=["POST"])
def final_score():
    results = request.form["score_give"]
    num = results
    # db에 점수를 가지고 조회해서 알맞는 결과 문장 가져오는 코드 작성
    return jsonify({'result': num})


if __name__ == '__main__':
    app.run('0.0.0.0', port=5000, debug=True)

mongodb, flask, dnspython 사용

 

 

 

 

 

test.html ( html, js ) 

        function show_quiz() {
            fetch(`/quiz`).then((res) => res.json()).then((data) => {
                let rows = data['result'][quiz_num - 1]
                let NUM = rows['NUM']
                let A_C = rows['A_C']
                let B_C = rows['B_C']
                let C_C = rows['C_C']
                let D_C = rows['D_C']
                let A_S = rows['A_S']
                let B_S = rows['B_S']
                let C_S = rows['C_S']
                let D_S = rows['D_S']
                console.log(rows);
                $('#lv').empty()
                let lv_html = `<span id="lv">0${NUM}</span>`
                $('#lv').append(lv_html)
                $('#box').empty()
                let color_html = `<div class="quiz-box" id="box">
                                        <button class="quiz-button" style="background-color:${A_C}" onclick="next_quiz(${A_S})"></button>
                                        <button class="quiz-button" style="background-color:${B_C}" onclick="next_quiz(${B_S})"></button>
                                        <button class="quiz-button" style="background-color:${C_C}" onclick="next_quiz(${C_S})"></button>
                                        <button class="correct-button" style="background-color:${D_C}" onclick="next_quiz(${D_S})"></button>
                                    </div>`
                $('#box').append(color_html)
            })
        }

        function next_quiz(a) {
            let score = a
            if (score == 1) {
                total_score++;
                quiz_num++;
            } else {
                quiz_num++;
            }

            if (quiz_num === 11){
                let formData = new FormData();
                formData.append("score_give", total_score);

                fetch('/final/score', {method: "POST",body: formData,}).then((res) => res.json()).then((data) => {
                    let total_score = data['result']
                    window.location.href = '/final?total_score=' + total_score
                });
            }
           
                console.log(total_score, quiz_num)
                fetch(`/quiz`).then((res) => res.json()).then((data) => {
                    let rows = data['result'][quiz_num - 1]
                    let NUM = rows['NUM']
                    let A_C = rows['A_C']
                    let B_C = rows['B_C']
                    let C_C = rows['C_C']
                    let D_C = rows['D_C']
                    let A_S = rows['A_S']
                    let B_S = rows['B_S']
                    let C_S = rows['C_S']
                    let D_S = rows['D_S']
                    $('#lv').empty()
                    let lv_html = `<span id="lv">0${NUM}</span>`
                    $('#lv').append(lv_html)
                    $('#box').empty()
                    let color_html = `<div class="quiz-box" id="box">
                                        <button class="quiz-button" style="background-color:${A_C}" onclick="next_quiz(${A_S})"></button>
                                        <button class="quiz-button" style="background-color:${B_C}" onclick="next_quiz(${B_S})"></button>
                                        <button class="quiz-button" style="background-color:${C_C}" onclick="next_quiz(${C_S})"></button>
                                        <button class="correct-button" style="background-color:${D_C}" onclick="next_quiz(${D_S})"></button>
                                    </div>`
                    $('#box').append(color_html)
                   
                })
           


        }
    </script>
</head>
<body class="body-color">
<header>
    <div class="topinfo">
        <div class="level">
            Level<span id="lv">01</span>
        </div>
        <div id="times"></div>
    </div>
</header>
<section>
    <div class="wrap">
        <div class="quiz-box" id="box">
            <div class="quiz-box">
                <button class="quiz-button" onclick="next_quiz(A_S)" style="background-color:#282828"></button>
                <button class="quiz-button" onclick="next_quiz(B_S)" style="background-color:#3c3c3c"></button>
                <button class="quiz-button" onclick="next_quiz(C_S)" style="background-color:#282828"></button>
                <button class="correct-button" onclick="next_quiz(D_S)" style="background-color:#282828"></button>
            </div>
        </div>
    </div>
</section>

 

 

 

 

html

<div class="share-box">
                <div class="share">내 점수 공유하기</div>
                <br>
                <div class="share-ring">
                <a href="javascript:kakao();" class="sharekakao">
                </a>
                <a href="javascript:facbook();" class="sharefacebook">
                </a>
                <a href="javascript:band();" class="shareband">
                </a>
                <a href="javascript:twitter();" class="sharetwitter">
                </a>
            </div>

 


 

 

 

css

.share-box {

    width: 311px;
    height: 92px;
    left: 564px;
    top: 749px;
   
    background: #FDFFE8;
    border-radius: 20px;

    margin: auto;
    margin-top: 79px;

}


.share {

   
   
    font-family: 'Inter';
    font-style: normal;
    font-weight: 400;
    font-size: 20px;
    line-height: 24px;

   
   
    color: #124019;

}

 


 

JavaScript 

트위터, 페이스북, 밴드

  <script>
        function twitter() {
        let sendText = "색감 테스트 나의 점수는??"; // 전달할 텍스트
        let sendUrl = "final.html"; // 전달할 URL (도메인 서버 오픈 후 url 입력)
        window.open("https://twitter.com/intent/tweet?text=" + sendText + "&url=" + sendUrl);
    }
        function facbook() {
       
        let sendUrl = "final.html"; // 전달할 URL (도메인 서버 오픈 후 url 입력)
        window.open("http://www.facebook.com/sharer/sharer.php?u=" + sendUrl);
    }
        function band() {
           
            let sendUrl = "final.html"; // 전달할 URL (도메인 서버 오픈 후 url 입력)
            window.open("http://band.us/plugin/share?body" + sendUrl);
        }

    </script>

 


 

 

 

JavaScript 

카카오톡

 

 <script>
         // SDK를 초기화 합니다. 사용할 앱의 JavaScript 키를 설정
        Kakao.init('a80a498adf2f919c5b8a90f0e35b0a3f');

        // SDK 초기화 여부를 판단
        console.log(Kakao.isInitialized());

        function kakao() {
        Kakao.Link.sendDefault({
            objectType: 'feed',
            content: {
            title: '색감 테스트!!',
            description: '색감 테스트로 색 구별 능력을 테스트 해보세요!',
            link: {
                mobileWebUrl: 'https://www.naver.com/', //나중에 도메인 생성 후 입력 (카카오 디벨로퍼에도 도메인 추가)
                webUrl: 'https://www.naver.com/', //나중에 도메인 생성 후 입력 (카카오 디벨로퍼에도 도메인 추가)
            },
            },
            buttons: [
            {
                title: '웹으로 보기',
                link: {
                mobileWebUrl: 'https://www.naver.com/',//나중에 도메인 생성 후 입력 (카카오 디벨로퍼에도 도메인 추가)
                webUrl: 'https://www.naver.com/',//나중에 도메인 생성 후 입력 (카카오 디벨로퍼에도 도메인 추가)
                },
            },
            ],
            // 카카오톡 미설치 시 카카오톡 설치 경로이동
            installTalk: true,
        })
        }  
            </script>

 

 

 

 

카카오톡에 공유하려면, 카카오 개발자 사이트에 회원가입 및 애플리케이션 등록 절차가 필요

 

내 애플리케이션 -> 애플리케이션 추가하기

 

앱 이름, 사업자명 임의로 입력 

 

JavaScript 키 복사

 

 

 

내 애플리케이션 > 앱 설정 > 플랫폼 > Web 플랫폼 등록

 

 

아직 테스트 단계라 기본 도메인 naver 입력 

등록된 도메인에서 실행해야 오류가 나지 않기 때문에 테스트용 locallhost 같이 등록

 

 

 

 

 

 

클릭 시 naver.com 이동

 

 

 <script>
        let SetTime = 30;      // 최초 설정 시간(기본 : 초)
        function msg_time() {   // 1초씩 카운트      
        m = Math.floor(SetTime / 60)  + (SetTime % 60) + "초"; // 남은 시간 계산        
        let msg = "<font>" + m + "</font>";  
        document.all.times.innerHTML = msg;     // div 영역에 보여줌                  
        SetTime--;                  // 1초씩 감소
        if (SetTime < 0) {          // 시간이 종료 되었으면..        
            clearInterval(tid);     // 타이머 해제
            window.location.href='/final'

        }      
    }
    window.onload = function TimerStart(){ tid=setInterval('msg_time()',1000) };
    </script>

 

색감테스트 시간 30초 설정 -> 시간 종료 시 final.html로 이동

 

 

app.py

 

from flask import Flask, render_template ,url_for
app = Flask(__name__)

@app.route('/')
def home():
   return render_template('index.html')

@app.route('/test')
def test():
   return render_template('test.html')

@app.route('/final')
def final():
   return render_template('final.html')

if __name__ == '__main__':  
   app.run('0.0.0.0',port=5000,debug=True)

서버는 파이썬활용 Flask, dnspython 사용

 

 

 

index.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <link rel="stylesheet" href="{{ url_for('static', filename='css/style.css') }}">
    <title>색감 구별 테스트 나의 점수는??</title>
</head>
<body class="body-color">
<section>
    <div class="wrap">
        <div class="description">
            <h5>
                <img src="https://blog.kakaocdn.net/dn/dvObbX/btrXVyFbLjz/SOBHasvaTPj2xm8pO909R1/img.png"> <!-- 작은 색감테스트 이미지 -->
                색감테스트</h5>
            <p>다른 색상 하나를 찾아보세요.</p>
            <p>시간 제한 10초!!</p>
        </div>
        <div>
            <h1>
                <img src="https://blog.kakaocdn.net/dn/Qm9gG/btrXUrmyMAk/nQoWGqLW4qOsWj8GNpOh00/img.png" height="369" width="366"/> <!-- 메인 이미지 -->
            </h1>
        </div>
        <div>
            <h1>
                색감 구별 테스트
            </h1>
        </div>
        <div>
            <h3>색감 테스트 4개 중 다른 것을 찾아보세요!</h3>
        </div>
        <div>
            <button class="mybutton" type="button" onclick="window.location.href='/test'"> > 테스트 시작!</button>
        </div>
    </div>
</section>
</div>
</body>
</html>

 

 

 

 

style.css

 

* {
    font-family: 'Jua', sans-serif; /*전체 글씨체 변경*/
}

.body-color {
    background-color: lightgray; /*전체 body color*/
}

.wrap {
    width: 400px;
    margin: auto; /*body 전체 클래스로 묶고 가운데 정렬*/
    padding-top: 200px;
}


h5 {

    font-style: normal;
    font-weight: 400;
    font-size: 30px;
    line-height: 36px;

    margin-bottom: 20px;

    color: #6886A2;

}

p {


    font-style: normal;
    font-weight: 400;
    font-size: 20px;
    line-height: 18px;


    color: #000000;


}






.mybutton {

    margin-top: 50px;
    margin-left: 60px;


    font-style: normal;
    font-weight: 400;
    font-size: 25px;
    line-height: 30px;
    text-align: center;
    color: #FFFFFF;


    box-sizing: border-box; /*버튼 박스 */
    background: #89A7C3;
    border: 1px solid #89A7C3;
    box-shadow: 0px 4px 4px rgba(0, 0, 0, 0.25);
    border-radius: 20px;
    padding-top: 5px;
    width: 242px;
    height: 47px;
    left: 599px;
    top: 809px;

}

.mybutton:hover {
    border: 2px solid white;
}


 

 

테스트 시작! button 클릭 시 test.html 파일로 이동하게 설정

 

 


test.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <link rel="stylesheet" href="{{ url_for('static', filename='css/style2.css') }}">
    <title>색감 구별 테스트 나의 점수는??</title>


</head>
<body class="body-color">

    <header>
        <div class="topinfo">
            <div class="level">
                Level<span id="score">1</span>
            </div>

            <div id="times"></div>


        </div>
    </header>

<section>
    <div class="wrap">
       
        <div class="quiz-box">
            <button class="quiz-button" onclick="checkQuiz('wrong')"></button>
            <button class="quiz-button" onclick="checkQuiz('wrong')"></button>
            <button class="quiz-button" onclick="checkQuiz('wrong')"></button>
            <button class="correct-button" onclick="checkQuiz('correct')"></button>
        </div>
       
           
    </div>
</section>
</div>
</body>
</html>

 

 

 

style2.css

* {
    font-family: 'Jua', sans-serif; /*전체 글씨체 변경*/
}

.body-color {
    background-color: lightgray; /*전체 body color*/
}

.wrap {


    width: 400px;
    margin: auto; /*body 전체 클래스로 묶고 가운데 정렬*/
    padding-top: 200px;
}


.topinfo {

    display: flex;
    background-color: #FBFFEE;

    justify-content: space-between;

    height: 87px;
   
   
}

.level {

width: 97px;
height: 36px;
left: 84px;
top: 26px;

font-family: 'Inter';
font-style: normal;
font-weight: 400;
font-size: 30px;
line-height: 36px;

color: #000000;

margin-top: 26px;
margin-left: 84px;



}

#score {

    color: red;
   
   
}

#times {

width: 120px;
height: 36px;
left: 1243px;
top: 26px;

font-family: 'Inter';
font-style: normal;
font-weight: 400;
font-size: 30px;
line-height: 36px;

color: red;

margin-top: 26px;



}

.quiz-button {

    width: 181px;
    height: 181px;
    left: 536px;
    top: 328px;
   
    background: #FF8B8B;

   
   
   

}

.correct-button {
    width: 181px;
    height: 181px;
    left: 536px;
    top: 328px;
   
    background: rgba(255, 139, 139, 0.55);

}

 

 

 

Level, time (카운트다운), box(문제) 레이아웃 구현

 


final.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <link rel="stylesheet" href="{{ url_for('static', filename='css/style3.css') }}">
    <title>색감 구별 테스트 나의 점수는??</title>
</head>
<body class="body-color">

<section>
    <div class="wrap">

        <div class="final-container">
            <p>색감테스트 당신의 level은</p>
            <strong class="level">3</strong>
            <p class="comment">오? 보통은 아닌데요? 센스가 있어요</p>
       
            <div class="reset" >
                <button class="btn-again" onclick="window.location.href='/'">다시 도전 !</button>
            </div>
       
            <div class="share-box">
                <div class="share">내 점수 공유하기</div>
                <br>
                <div class="share-ring">
                <a href="javascript:;" class="sharekakao">
                </a>
                <a href="javascript:;" class="shareinstagram">
                </a>
                <a href="javascript:;" class="shareFb">
                </a>
                <a href="javascript:;" class="shareband">
                </a>
                <a href="javascript:;" class="sharetwitter">
                </a>
            </div>
            </div>


           

        </div>



       

       
           
    </div>
</section>
</div>
</body>
</html>

 

 

style3.css

 
* {
    font-family: 'Jua', sans-serif; /*전체 글씨체 변경*/
}

.body-color {
    background-color: lightgray; /*전체 body color*/
}

.wrap {
    width: 800px;
    height: 1000px;
    margin: auto; /*body 전체 클래스로 묶고 가운데 정렬*/
    padding-top: 200px;  
}

.final-container {

    width: 722px;
    height: 220px;
    left: 359px;
    top: 309px;
   
    background: #FFFDFD;
    border-radius: 20px;

    text-align: center;

    margin: auto;
}

p {
width: 751px;
height: 36px;
left: 494px;
top: 459px;

font-family: 'Inter';
font-style: normal;
font-weight: 400;
font-size: 30px;
line-height: 36px;

color: #000000;
}

.level {

font-size: 50px;
color: blue;

}

.reset {

margin-top: 100px;

}


.btn-again {

width: 220px;
height: 79px;
left: 610px;
top: 591px;

background: #FE8686;
border-radius: 20px;
border-color: #FE8686;

font-family: 'Inter';
font-style: normal;
font-weight: 400;
font-size: 20px;
line-height: 24px;
text-align: center;

color: #FFFFFF;

}
.btn-again:hover {
    border: 0.5px solid white;
}

.share-box {

    width: 311px;
    height: 92px;
    left: 564px;
    top: 749px;
   
    background: #FDFFE8;
    border-radius: 20px;

    margin: auto;
    margin-top: 79px;

}


.share {

   
   
    font-family: 'Inter';
    font-style: normal;
    font-weight: 400;
    font-size: 20px;
    line-height: 24px;

   
   
    color: #124019;

}


 

맞춘 갯수 만큼 level과 comment 변경 할수 있게 레이아웃 구현

다시 도전! 버튼 클릭시 첫 페이지로 돌아갈수있게 페이지 새로고침 구현

sns에 공유 가능하게 이미지별 버튼 구현

 

 

Main Page

https://www.figma.com/proto/B3x6kCaa7gzb3nXKpAhcQw/Untitled?page-id=0%3A1&node-id=0%3A3&viewport=693%2C505%2C0.57&scaling=min-zoom 

 

 

 

 

Test Page

https://www.figma.com/proto/B3x6kCaa7gzb3nXKpAhcQw/Untitled?page-id=1%3A2&node-id=5%3A64&viewport=619%2C415%2C0.36&scaling=min-zoom 

 

 

 

Final Page

https://www.figma.com/proto/B3x6kCaa7gzb3nXKpAhcQw/Untitled?page-id=1%3A3&node-id=9%3A11&viewport=497%2C511%2C0.36&scaling=min-zoom 

 

+ Recent posts