TOY_PROJECT(4)
-
Read
@app.route('/') def home(): return render_template('index.html') app.py를 render_template을 활용해 index.html과 연결해주었다. # 링크 전체 조회 @app.route("/api/link", methods=["GET"]) def link_list_get(): _linklist = list(db.links.find({}, {'_id': False})) return jsonify({'linklist': _linklist}) GET을 활용해 /api/link로 연결했다 _linklist는 db의 links에서 _id값을 제외한 모든 값을 가져와 나열해준다. 이후 프론트엔드 linklist와 연결해준다. 이를 통해 백엔드 데이터를 프론트..
2023.01.13 -
Create
토이프로젝트를 진행하며, 혜민님의 도움을 받아 가장 기본적인 설계부터 진행했다. Create 생성 Read 읽기 Update 갱신 Delete 삭제 기능을 먼저 구현하기 위해 app.py코드를 채워나갔다. # 링크 생성 Create @app.route("/api/link", methods=["POST"]) def link_post(): POST라는 methods를 사용해서 /api/link를 통해 연결한다. link_post()라고 정의한 내용이다. # id 값 만들기 all_list = list(db.links.find({}, {'_id': False})) id = len(all_list) + 1 title = request.form['title'] url = request.form['url'] tag..
2023.01.13 -
ajax
같이 영현님이 짜신 코드를 보면서 cache , contentType , processData 를 모두 false 로 세팅한 것을 봤다. 파일을 보내는데 필요한 기본 세팅이 되어있지 않을 수 있기 때문에 cache , contentType , processData 를 모두 false 로 세팅해준다는 것을 알았다.
2023.01.13 -
Toy_project #1
@app.route("/api/link", methods=["POST"]) def link_post(): title = request.form['title'] url = request.form['url'] tag = request.form['tag'] author = request.form['author'] image = request.form['image'] count = list(db.links.find({}, {'_id': False})) id = len(count) + 1 doc = { 'id': id, 'title': title, 'url': url, 'tag': tag, 'author': author, 'image': image } db.links.insert_one(doc) return js..
2023.01.10