Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 | 29 |
30 | 31 |
Tags
- 2003 error
- 미국 이란 전쟁
- 110 옮기기
- 스무고개 Metric
- 뤼이드
- 2003 에러
- 경제 요약
- git-lfs
- 알고리즘
- 리멤버나우
- 이베이 매각
- 코딩테스트
- but how?
- pytorch-tutorial
- 딥러닝
- flask
- 프로그래머스 여행경로
- git password
- 장영준
- aws rds
- cs231
- 오픈소스
- Convolutional Neural Networks
- C++
- multi-task learning
- 백준 2193
- 리멤버나우 요약
- flaks
- 웹 독학
- 프로그래머스
Archives
- Today
- Total
Nam's
Flask Study 03 - Marshmallow 본문
marshmallow is an ORM/ODM/framework-agnostic library for converting complex datatypes, such as objects, to and from native Python datatypes. - marshmallow.readthedocs.io/en/latest/
[공식 예제]
1
2
3
4
5
6
7
|
from your_orm import Model, Column, Integer, String, DateTime
class User(Model):
email = Column(String)
password = Column(String)
date_created = Column(DateTime, auto_now_add=True)
|
cs |
[내 예제]
1
2
3
4
5
6
7
8
9
10
11
12
|
from marshimallow import fields
from marshmallow_sqlalchemy import ModelSchema
from models import Machine
class UserSchema(ModelSchema):
class Meta:
# Fields to expose
fields = ("email", "date_created")
user_schema = UserSchema()
users_schema = UserSchema(many=True)
|
cs |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
def users():
all_users = User.all()
return users_schema.dump(all_users)
@app.route("/api/users/<id>")
def user_detail(id):
user = User.get(id)
return user_schema.dump(user)
# {
# "email": "fred@queen.com",
# "date_created": "Fri, 25 Apr 2014 06:02:56 -0000",
# }
|
cs |
'개발 > Back-end' 카테고리의 다른 글
[AWS] EC2 초기 환경 설정 (0) | 2021.04.03 |
---|---|
Flask Study 04 - SQLAlchemy filter, filter_by (or, !=, like) (0) | 2021.02.17 |
Flask Study 02 - DB Migration (0) | 2021.01.26 |
Flask Study 01 - host 설정 (0) | 2021.01.25 |
Flask 디버깅 03 - Load_dotenv로 .env 가져오기 (0) | 2021.01.23 |
Comments