편집 기록

편집 기록
  • 프로필 엽토군님의 편집
    날짜2019.06.21

    flask로 구현한 웹 페이징하는 방법에 대해 질문 올립니다


    @app.route('/main', methods=['GET'])
    def test():
        test_list = []
        test_items = db.session.query(table_class_name).filter(table_class_name.column == 150 ).limit(9).all()
        for item in test_items:
           test_dict = {}
           test_dict['name1'] = test_items.name
           test_dict['id'] = test_items.id
           test_list.append(test_dict)
       dump_data = json.dumps(test_list)
        return render_template('test.html', dump_data=dump_data)
    
    
    @app.route('/pagination', methods=['GET'])
    def test_paging():
        limit_num =  request.args.get('num')
        test_list = []
       test_items = db.session.query(table_class_name).filter(table_class_name.column == 150 ).limit(9).all()  # 이부분에 리미트 범위를 둬야합니다!!!!!!!!!!!!!!!!
        for item in test_items:
           test_dict = {}
           test_dict['name1'] = test_items.name
           test_dict['id'] = test_items.id
           test_list.append(test_dict)
       dump_data = json.dumps(test_list)
        return dump_data
    
    

    우선 위의 함수들은 예시인점 감안해주시고 질문 읽어주시면 감사하겠습니다
    현재 최종적으로 만들려는 기능이 flask로 구현한 웹의 한 페이지에 어떤 정보들이 순차적으로 나열 되어 보여지는데 그것의 처음 데이터 개수가 9개입니다.
    추가적으로 데이터를 보기위해서 read more 버튼을 눌렀을 때 5개씩 데이터가 보여지게끔 만들고 싶습니다
    위의 코드는 '/main'이란 페이지에서 read more을 눌렀을 때 '/pagination'이란 곳에서 리미트 구간을 적용해서 이전에 9개 데이터가 웹에 뿌려져있으니까 9개 이후의 추가 5개만 더 가져오게끔 만들고 싶습니다.
    그래서 html문서에서는 '/pagination'에 ajax로 값을 넘겨주고 받는 형식으로 작성 해두었는데 read more을 누를 때마다 추가적인 데이터가 5개씩 넘어오도록 어떻게 작성해야가능한가요?
    우선 제가 생각한 방법은 read more을 눌렀을 때 num이란 곳에 5를 부여해서 json형태로 5라는 숫자를 넘기고 '/paginatnion'에서 5라는 숫자를 받고 첫 번째 클릭 했을 때는 limit 11~15 만큼 데이터가 오고 그 다음에는 처음에 넘어왔던 5에 추가적으로 5가 더해져서 10이되고 limit 16~20인 부분의 데이터가 다시 넘어오게끔 만들려 했는데 read more을 눌렀을 때마다 5라는 숫자가 어떻게 더해지게 해야되는지와 sqlalchemy를 사용한 부분에서 limit함수 문법을 어떻게 해야하는지 모르겠습니다 sqlalchemy limit 사용법도 같이 알려주시면 감사하겠습니다
    질문과 관련해서 구글링을해봐도 접근자체를 잘 모르는 상태라 필요한 정보가 안 나오네요

  • 프로필 김재민님의 편집
    날짜2019.06.21

    flask로 구현한 웹 페이징하는 방법에 대해 질문 올립니다


    @app.route('/main', methods=['GET'])
    def test():
        test_list = []
        test_items = db.session.query(table_class_name).filter(table_class_name.column == 150 ).limit(9).all()
        for item in test_items:
           test_dict = {}
           test_dict['name1'] = test_items.name
           test_dict['id'] = test_items.id
           test_list.append(test_dict)
       dump_data = json.dumps(test_list)
        return render_template('test.html', dump_data=dump_data)
    
    
    @app.route('/pagination', methods=['GET'])
    def test_paging():
        limit_num =  request.args.get('num')
        test_list = []
       test_items = db.session.query(table_class_name).filter(table_class_name.column == 150 ).limit(9).all()  # 이부분에 리미트 범위를 둬야합니다!!!!!!!!!!!!!!!!
        for item in test_items:
           test_dict = {}
           test_dict['name1'] = test_items.name
           test_dict['id'] = test_items.id
           test_list.append(test_dict)
       dump_data = json.dumps(test_list)
        return dump_data
    
    

    우선 위의 함수들은 예시인점 감안해주시고 질문 읽어주시면 감사하겠습니다 현재 최종적으로 만들려는 기능이 flask로 구현한 웹의 한 페이지에 어떤 정보들이 순차적으로 나열 되어 보여지는데 그것의 처음 데이터 개수가 9개입니다. 추가적으로 데이터를 보기위해서 read more 버튼을 눌렀을 때 5개씩 데이터가 보여지게끔 만들고 싶습니다 위의 코드는 '/main'이란 페이지에서 read more을 눌렀을 때 '/pagination'이란 곳에서 리미트 구간을 적용해서 이전에 9개 데이터가 웹에 뿌려져있으니까 9개 이후의 추가 5개만 더 가져오게끔 만들고 싶습니다. 그래서 html문서에서는 '/pagination'에 ajax로 값을 넘겨주고 받는 형식으로 작성 해두었는데 read more을 누를 때마다 추가적인 데이터가 5개씩 넘어오도록 어떻게 작성해야가능한가요? 우선 제가 생각한 방법은 read more을 눌렀을 때 num이란 곳에 5를 부여해서 json형태로 5라는 숫자를 넘기고 '/paginatnion'에서 5라는 숫자를 받고 첫 번째 클릭 했을 때는 limit 11~15 만큼 데이터가 오고 그 다음에는 처음에 넘어왔던 5에 추가적으로 5가 더해져서 10이되고 limit 16~20인 부분의 데이터가 다시 넘어오게끔 만들려 했는데 read more을 눌렀을 때마다 5라는 숫자가 어떻게 더해지게 해야되는지와 sqlalchemy를 사용한 부분에서 limit함수 문법을 어떻게 해야하는지 모르겠습니다 sqlalchemy limit 사용법도 같이 알려주시면 감사하겠습니다 질문과 관련해서 구글링을해봐도 접근자체를 잘 모르는 상태라 필요한 정보가 안 나오네요