[스파르타7기] 개발일지3 - 2020.04.19

Tia Hwang·2020년 4월 19일
0

스파르타7기

목록 보기
4/12

오늘한일

1. 이메일별로 등록된 습관들 불러오기 + username 표시

  • global 변수선언
current_email = ''
  • 로그인한 이메일을 전역변수로 저장
@app.route('/habits', methods=['POST'])
def saving():
    global current_email
    email_receive = request.form['email']
    habits_receive = request.form.getlist('habits[]')

    current_email = email_receive
  • 저장된 전역변수 활용
    • db에 저장된 이메일과 로그인한 이메일(저장된 전역변수)이 같다면 그 이메일에 등록된 습관 불러오기
    • 로그인한 이메일(저장된 전역변수)를 이용해 username 설정
@app.route('/habits', methods=['GET'])
def listing():
    global current_email
    habit_list = list(db.habits.find({}, {'_id': 0}))
    
    user_habit_list = []
    
    for habit in habit_list:
        if habit['email'] == current_email:
            user_habit_list.append(habit)
            
    username=current_email.split("@")[0]
    return render_template("habits.html", email=username, habits=user_habit_list)
  • 출력된 화면

해야할일

1. 습관을 달력에 저장하면 db에 저장하기(현재 refresh하면 정보 날라감)

2. 이미 등록된 이메일의 경우, 달력정보 불러오는 방법

=> 따로 버튼을 만들어야하는가?

GitHub commit

profile
프론트엔드 개발자로 취업하기

0개의 댓글