• Stars
    star
    117
  • Rank 301,828 (Top 6 %)
  • Language
    Python
  • License
    MIT License
  • Created over 7 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

This is how I structure my large Flask applications.

Flask-Large-Application-Example

Scrutinizer Code Quality Codacy BadgeCode style: black

This is how I structure my large Flask applications.

About

๋งˆ์ดํฌ๋กœ ์›น ํ”„๋ ˆ์ž„์›Œํฌ์ธ Flask๋Š” ํ•ญ์ƒ ๊ฐœ๋ฐœ์ž์—๊ฒŒ ๊ตฌ์กฐ์— ๋Œ€ํ•œ ๊ณ ๋ฏผ์„ ํ•˜๊ฒŒ ๋งŒ๋“ญ๋‹ˆ๋‹ค. ์ด ์ €์žฅ์†Œ๋Š” ์ œ๊ฐ€ Flask๋ฅผ ๋ฐฐ์šฐ๊ธฐ ์‹œ์ž‘ํ–ˆ๋˜ ๊ณ ๋“ฑํ•™๊ต 1ํ•™๋…„ ๋•Œ๋ถ€ํ„ฐ ์ง€๊ธˆ๊นŒ์ง€์˜ ์‹œ๊ฐ„๋™์•ˆ Flask ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜์˜ ๊ตฌ์กฐ์— ๋Œ€ํ•ด ๊ณ ๋ฏผํ•œ ํ”์ ์ž…๋‹ˆ๋‹ค. ๊ทผ๋ฐ ๋ญ ๊ณ„์† ๊ฐœ์„ ํ•˜๋‹ค ๋ณด๋‹ˆ๊นŒ Flask์—๊ฒŒ๋งŒ ํŠน๋ณ„ํžˆ ์ ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ๊ตฌ์กฐ๋ผ๊ธฐ ๋ณด๋‹จ ๋‹ค๋ฅธ ์›น ํ”„๋ ˆ์ž„์›Œํฌ๋“ค์—์„œ๋„ ์จ๋จน์„ ์ˆ˜ ์žˆ๋Š” ๊ธฐ๋ฐ˜์ด ๋  ์ˆ˜๋„ ์žˆ์„ ๊ฒƒ ๊ฐ™๋„ค์š”.

๊ตฌ์กฐ๊ฐ€ ๋ง‰ ๋นก์„ธ๋‹ค๊ณ  ์ข‹์•„์ง€๋Š” ๊ฑด ์•„๋‹Œ ๊ฒƒ ๊ฐ™์•„์„œ, ์กฐ๊ธˆ ํŽธํ•˜๋ ค๊ณ  ๋ณต์žก๋„๋ฅผ ๋†’์—ฌ๋ฒ„๋ฆฌ๋Š” ๋ชจ์Šต์€ ์ง€์–‘ํ–ˆ์Šต๋‹ˆ๋‹ค. ์ด ๋ ˆํฌ์˜ '์ตœ์‹  ๋ฒ„์ „'์€ ํ•ญ์ƒ ์ œ ๊ธฐ์ค€์—์„  ๊ฐ€์žฅ ํŽธํ•œ ๊ตฌ์กฐ์ธ๋ฐ, ๋ชจ๋‘์—๊ฒŒ ๊ทธ๋ ‡์ง€๋„ ์•Š๊ณ  ์ €๋„ ์ž์ฃผ ๋งˆ์Œ์ด ๋ฐ”๋€๋‹ˆ๋‹ค. ๋ณ„๊ฑฐ ์•„๋‹Œ ์ฝ”๋“œ์— ์ปค๋ฐ‹์ด ๋ฐฑ๋‹จ์œ„์ธ ๊ฒŒ ์ด๋Ÿฐ ์ด์œ ๋‹ˆ๊นŒ, ๊ทธ๋ƒฅ ์ด๊ฑฐ ๊ฐ€์ ธ๊ฐ€์„œ ๋ณธ์ธํ•œํ…Œ ๋งž๊ฒŒ ์ปค์Šคํ…€ํ•˜์‹œ๋ฉด ์ข‹์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹น ใ…Žใ…Ž

์ปจ์…‰

application factory๊ฐ€ ํ•„์š”ํ•˜๋‹ค.(app/__init__.py)

local์—์„œ ์‹คํ–‰ํ•ด๋ณด๋Š” ์šฉ๋„, ํ…Œ์ŠคํŠธ ํด๋ผ์ด์–ธํŠธ๋ฅผ ์–ป๋Š” ์šฉ๋„, ๋ฐฐํฌ ๋‹จ์—์„œ ์‚ฌ์šฉํ•˜๋Š” ์šฉ๋„ ๋“ฑ์œผ๋กœ app ๊ฐ์ฒด๊ฐ€ ํ•„์š”ํ•œ๋ฐ, ๊ทธ๋“ค์€ ๋ชจ๋‘ extension ์ดˆ๊ธฐํ™” - view๋“ค ๋ผ์šฐํŒ… - hook ๋‹ฌ์•„์ฃผ๋Š” ๊ฒƒ์€ ๋˜‘๊ฐ™๊ณ , ๋‹จ์ง€ ์ฃผ์ž…๋˜๋Š” config๊ฐ€ ๋‹ค๋ฅธ ๊ฒƒ๋ฐ–์— ์ฐจ์ด๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค. create_app์—์„œ config class๋“ค์„ ๋ฐ›๋„๋ก ํ–ˆ์Šต๋‹ˆ๋‹ค.

extension๋“ค์€ lazyํ•˜๊ฒŒ ์ดˆ๊ธฐํ™”ํ•œ๋‹ค.(app/extensions.py, app/__init__.py์˜ register_extensions)

์–ด๋–ค config๋ฅผ ์ฃผ์ž…ํ• ์ง€๋Š” create_app ํ•จ์ˆ˜๊ฐ€ ํ˜ธ์ถœ๋œ ํ›„ ์ •ํ•ด์ง€๋ฏ€๋กœ, config์— ์˜ํ•ด ์ดˆ๊ธฐํ™”๊ฐ€ ์ง„ํ–‰๋˜๋Š” extension๋“ค์€ lazyํ•˜๊ฒŒ ์ดˆ๊ธฐํ™”ํ•˜๋„๋ก ํ–ˆ์Šต๋‹ˆ๋‹ค.

config๋ฅผ ๋”ฐ๋กœ ํŒจํ‚ค์ง€ํ™”ํ•ด์„œ, ์„ ํƒ์ง€๋ฅผ ๋‘์–ด ๊ด€๋ฆฌํ•œ๋‹ค.(config/)

  1. Flask์—์„œ config๋Š” class๋กœ ๋‹ค๋ฃจ๋Š” ๊ฒŒ ๊ฐ€์žฅ ์ข‹๋‹ค๊ณ  ์ƒ๊ฐํ•ฉ๋‹ˆ๋‹ค.
  2. Config๋Š” ์ •์ ์ด์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. Config class ๋‚ด์—์„œ if์ ˆ์ด ์žˆ๋Š” ํ˜•ํƒœ๋Š” ์ข‹์ง€ ์•Š๋‹ค๊ณ  ์ƒ๊ฐํ•ฉ๋‹ˆ๋‹ค. ํ™˜๊ฒฝ ๋ณ€์ˆ˜์— ๋”ฐ๋ผ ์„œ๋กœ ๋‹ค๋ฅธ config๋ฅผ ์ฃผ์ž…ํ•ด์•ผ ํ•œ๋‹ค๋ฉด, ๊ฐ๊ฐ์— ๋งž๊ฒŒ class๋ฅผ ๋‚˜๋ˆ„์–ด ์ค€๋น„ํ•œ ํ›„ create_app์„ ํ˜ธ์ถœํ•˜๋Š” ๋‹จ์—์„œ config๋ฅผ ์ƒํ™ฉ์— ๋งž๊ฒŒ ์ „๋‹ฌํ•˜๋„๋ก ๋งŒ๋“œ๋Š” ๊ฒŒ ์ข‹๋‹ค๊ณ  ๋ด…๋‹ˆ๋‹ค.
  3. ์„ ํƒ์ง€๋งˆ๋‹ค ๋ชจ๋“ˆ์„ ๋งŒ๋“ค์–ด ๋‘์—ˆ์Šต๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด, Local DB๋ฅผ ๋ฐ”๋ผ๋ณด๋„๋ก ํ•˜๋Š” config/Remote DB๋ฅผ ๋ฐ”๋ผ๋ณด๋„๋ก ํ•˜๋Š” config๋ฅผ db_config๋ผ๋Š” ๋ชจ๋“ˆ์— LocalDBConfig, RemoteDBConfig ํด๋ž˜์Šค๋กœ ์ค€๋น„ํ•œ๋‹ค.

์ƒ์ˆ˜ config๋Š” ๋”ฐ๋กœ ๊ด€๋ฆฌ๋˜์–ด์•ผ ํ•œ๋‹ค.(constants/)

DRYํ•œ ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•˜๊ธฐ ์œ„ํ•ด ๋ฆฌํ„ฐ๋Ÿด์„ ์ง€์–‘ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ๊ฒŒ์‹œ๊ธ€ ๋ชฉ๋ก API์—์„œ ๋ฐ˜ํ™˜ํ•ด์ฃผ๋Š” ๊ฒŒ์‹œ๊ธ€ ๊ธฐ๋ณธ ๊ฐฏ์ˆ˜๋‚˜, ํŠน์ • API์˜ ์‚ฌ์šฉ ๊ฐ€๋Šฅ ์‹œ๊ฐ„๊ฐ™์€ ๊ฒƒ๋“ค์„ ์˜ˆ๋กœ ๋“ค ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ด๋Ÿฐ ์ƒ์ˆ˜ config๋“ค์€ ๋”ฐ๋กœ ๊ด€๋ฆฌํ•ด์•ผ ํ•˜๋Š” ๊ฒƒ์€ ๋งž์ง€๋งŒ, ๊ตณ์ด app ๊ฐ์ฒด์— ์ฃผ์ž…ํ•  ํ•„์š”๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค. ๋”ฐ๋กœ ๋ชจ๋“ˆ๋งŒ ๋งŒ๋“ค์–ด ๋‘๋ฉด ๋จ.

blueprint์™€ flask_restful์ด ํ•„์š”ํ•˜๋‹ค.(app/views/_init_.py)

๋‹ค๋ฅธ ๋ณต์žกํ•œ ์ด์œ ๊ฐ€ ์•„๋‹ˆ๋ผ, ๋” ๊ตฌ์กฐ์ ์ธ ๋ผ์šฐํŒ…์„ ์œ„ํ•ด blueprint์˜ url prefix, flask_restful์˜ MethodView ํ™•์žฅ์ด ๋„์›€์„ ์ฃผ๊ธฐ ๋•Œ๋ฌธ์ž…๋‹ˆ๋‹ค.

context-dependentํ•œ ๋ฐ์ดํ„ฐ๋Š” ๋”ฐ๋กœ property classํ™” ์‹œํ‚จ๋‹ค.(app/context.py)

request, g ์ฒ˜๋Ÿผ contenxt-dependentํ•œ ๊ฐ์ฒด๋Š” attribute๊ฐ€ dynamicํ•˜๊ธฐ ๋•Œ๋ฌธ์—, known attribute๋ฅผ ๊ฐ€์ง€๋Š” ๊ฐ์ฒด๋ฅผ ๋งŒ๋“ค์–ด ์ค‘๊ณ„ํ•ด์ฃผ๋Š” ๊ฒŒ ์ข‹์Šต๋‹ˆ๋‹ค. ํœด๋จผ ์—๋Ÿฌ ์˜ˆ๋ฐฉ์— ๋„์›€์ด ๋˜๋”๋ผ๊ตฌ์š”.

request context๋ฅผ hookํ•˜๋Š” ์นœ๊ตฌ๋“ค์€ hook ํŒจํ‚ค์ง€์— ๋”ฐ๋กœ ๊ด€๋ฆฌํ•œ๋‹ค.(app/hooks/)

view function์ด ํ˜ธ์ถœ๋˜๊ธฐ ์ „์˜ ์ „์ฒ˜๋ฆฌ๋Š” view decorator๊ฐ€ ํ•˜๋Š” ๊ฒƒ์ด ๋งž๋‹ค.(app/decorators/)

I Referred

People

์ •๊ฒจ์šธ๋‹˜

Repository

Website

Explore Flask - Explore Flask 1.0 documentation
Organizing your project - Explore Flask 1.0 documentation
Patterns of Flask - Flask Documentation (0.12)
Larger Applications - Flask Documentation (0.12)
Application Structure | Flask(A Python Microframework)

How To Structure Large Flask Applications | DigitalOcean
How to Structure a Flask Application
Flask Large App How to - GitBook
Flask Project ๊ตฌ์กฐ ์˜ˆ์ œ - /usr/lib/libsora.so
StackOverflow - Common folder/file structure in Flask app

Presentation

Flask Hacks and Best Practices

More Repositories

1

google-play-scraper

Google play scraper for Python inspired by <facundoolano/google-play-scraper>
Python
745
star
2

Lets-Study

Let's Study.
643
star
3

--Awesome-Python--

ํŒŒ์ด์ฌ์— ๋Œ€ํ•œ ๊ฐ„๋‹จํ•œ ํŠœํ† ๋ฆฌ์–ผ + ํŒŒ์ด์ฌ์— ๊ด€ํ•œ ์˜ˆ์ œ ๋ชจ์•„๋‘๊ธฐ
Python
194
star
4

Sampleapp-for-blog

๋ธ”๋กœ๊ทธ์˜ '๋ฐฑ์—”๋“œ๊ฐ€ ์ด์ •๋„๋Š” ํ•ด์ค˜์•ผ ํ•จ' ์ปจํ…์ธ ๋ฅผ ์œ„ํ•œ ๋ ˆํฌ
Python
17
star
5

--Awesome-Kotlin--

Language with Concise Syntax based JVM
Kotlin
14
star
6

Daejeon-People

2017ํ•™๋…„๋„ SW๊ฐœ๋ฐœ๊ณผ ์ „๊ณต ํ”„๋กœ์ ํŠธ
Java
11
star
7

Blockchain-py

A simple Blockchain structured by Python
Python
10
star
8

Flask-Large-Application-Example-Simplified

Generalized, Simplified version of 'JoMingyu/Flask-Large-Application-Example'
Python
9
star
9

--Awesome-Go--

Supports GC, Concurrent, Classless, Compilation Language
Go
7
star
10

TIL

Let's Study์— ๋งํฌ๋ฅผ ๋ชจ์œผ๋Š” ์‹์œผ๋กœ ๊ณต๋ถ€ํ•˜๋‹ค ๋ณด๋‹ˆ ๊ทธ๋ƒฅ ๋ฌด์ฑ…์ž„ํ•˜๊ฒŒ ๋งํฌ๋งŒ ์˜ฌ๋ ค๋‘๊ณ  ๋๋‚˜๋Š” ๊ฒƒ ๊ฐ™์•„ ๋งŒ๋“  TIL
7
star
11

Django-Get-Started

์žฅ๊ณ ๋กœ ์†Œ๊ฟ‰๋†€์ด ใ…‹ใ…‹~
Python
6
star
12

Whale-GitPainter

Make your Github Profile more stylish!
JavaScript
6
star
13

Server-Quickstart-Vert.x

๐Ÿ“Œ Quickstart for Web Server Develop with Java&Vert.x
Java
6
star
14

opgg-helper

op.gg ์ฑ”ํ”ผ์–ธ ๋ถ„์„์— ๋น ๋ฅด๊ฒŒ ์ ‘๊ทผํ•˜๊ธฐ ์œ„ํ•œ CLI tool
Python
5
star
15

Ccomet-Howmuch-ExchangeRate

์‹ค์‹œ๊ฐ„ ํ™˜์œจ ์ •๋ณด ํ‘ธ์‰ฌ์•Œ๋ฆผ ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜
Python
5
star
16

--Awesome-NodeJS--

JIT-Compilation JS Runtime. Learn Express, Koa, Hapi
JavaScript
5
star
17

Helpable

12ํšŒ ์•ฑ์žผ : ์žฅ์• ์ธ ๋„์›€ ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜ API ์„œ๋ฒ„
Python
5
star
18

SaveTheHeartAttack

Android application for cardiac arrest patients and observers
Java
4
star
19

APmaker-for-Laptop

Access Point maker for Laptop
C++
3
star
20

TourAPI

'pip install tourapi' - TourAPI Parsing Library
Python
3
star
21

Whale-SideDish

Check the school meals on Whale's Sidebar.
JavaScript
3
star
22

--Awesome-Java--

Object-Oriented Language based JVM
Java
3
star
23

Bubble

์‚ฌ์ง„ ํ•„ํ„ฐ๋ง, ํ•„ํ„ฐ ์˜ต์…˜ ๊ณต์œ  ์•ฑ
Java
3
star
24

omakase-db-to-kakao-map

์ „๊ตญ ์˜ค๋งˆ์นด์„ธ ์Šค์‹œ์•ผ DB ์‹œํŠธ ๋ฐ์ดํ„ฐ ๊ฐ€์ง€๊ณ  ์นด์นด์˜ค๋งต์— ๋ถ๋งˆํฌ
Python
3
star
25

Voltalk

์—๋„ˆ์ง€ํ•ด์ปคํ†ค 2017 : ์„œ์šธ๋Œ€์— ์‹ฌ์–ด์ง„ ์—๋„ˆํ†ก ๋ฐ์ดํ„ฐ๋ฅผ ์กฐ๊ธˆ ๋” ์‰ฝ๊ฒŒ ๊ฐ€์ ธ์˜ค๊ธฐ ์œ„ํ•œ ์ค‘๊ณ„ API ์„œ๋ฒ„
Python
3
star
26

jomingyu.github.io

Ruby
2
star
27

Networking-Library-Java

HttpURLConnection์„ ์ด์šฉํ•ด REST๋กœ ๊ตฌ์„ฑ๋œ ์„œ๋ฒ„์™€ ํ†ต์‹ ํ•˜๊ธฐ ์œ„ํ•œ Java ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ
Java
2
star
28

Better-Flask-Application-For-Blog

๋ธ”๋กœ๊ทธ์˜ '๋” ์ข‹์€ Flask ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜ ๋งŒ๋“ค๊ธฐ' ์ปจํ…์ธ ๋ฅผ ์œ„ํ•œ ๋ ˆํฌ
Python
2
star
29

Schapi

'pip install schapi' - School Meal Data Parsing Library
Python
2
star
30

saketracker

Python
2
star
31

Flask-Guidebook

Flask์™€ Werkzeug์˜ ์†Œ์Šค์ฝ”๋“œ๋ฅผ ๋œฏ์–ด๋ณด๋ฉฐ ๋ฐฐ์šฐ๋Š” Flask
2
star
32

sushi-grid

์ธ์Šคํƒ€์— ์˜ฌ๋ฆฌ๋Š” ์Šค์‹œ ์‚ฌ์ง„ grid ๋งŒ๋“œ๋ ค๊ณ  ๋ณด๋‹ˆ ์•ฑ์— ๋ˆ ์จ์•ผ ํ•ด์„œ ์ง์ ‘ ๋งŒ๋“ฌ
Python
2
star
33

DMS-Migrates-to-Go

Go๋ฅผ ์—ฐ์Šตํ•˜๊ธฐ ์œ„ํ•ด, DMS ์„œ๋ฒ„๋ฅผ Go + Echo + MongoDB ๊ธฐ๋ฐ˜์œผ๋กœ ๋งˆ์ด๊ทธ๋ ˆ์ด์…˜ํ•˜๋Š” ์—ฐ์Šต์„ ํ•ด๋ณด์ž
Go
2
star
34

Performance-Test

์–˜๋Š” ์–ผ๋งˆ๋‚˜ ๋น ๋ฅผ๊นŒ? & ์–˜๋ž‘ ์–˜์ค‘์— ๋ญ๊ฐ€ ๋”, ์–ผ๋งˆ๋‚˜ ๋น ๋ฅผ๊นŒ? - ๋™์ผํ•œ ๊ฒฐ๊ณผ, ์„œ๋กœ ๋‹ค๋ฅธ ๋ฐฉ๋ฒ•์— ๋Œ€ํ•œ ํผํฌ๋จผ์Šค ํ…Œ์ŠคํŠธ๋“ค ์ •๋ฆฌ
Python
2
star
35

Study-Web

Let's Study Web Programming.
HTML
2
star
36

Ideasgrab-discord-bot

discord bot for https://www.ideasgrab.com/ updates
Python
2
star
37

Implementation

์ด๋Ÿฐ์ €๋Ÿฐ ์•Œ๊ณ ๋ฆฌ์ฆ˜ ๊ตฌํ˜„
1
star
38

--Awesome-BOJ--

Python
1
star
39

Chazatta-Backend

2017 ์ธํ•˜๋Œ€ํ•™๊ต ๋„ค์ด๋ฒ„D2 ์†Œํ”„ํŠธ์›จ์–ด ํ•ด์ปคํ†ค
JavaScript
1
star
40

Bobsim-Server

SW์—ฐํ•ฉ ํ•ด์ปคํ†ค ๋ฐฅ์‹ฌ ์„œ๋ฒ„
Java
1
star
41

Eraser

์ค‘๋ณต ํŒŒ์ผ ์‚ญ์ œ ํ”„๋กœ๊ทธ๋žจ
Java
1
star
42

JSON2SQL

JSON payload๋ฅผ SQL string์œผ๋กœ ๋ณ€ํ™˜ํ•ด์ฃผ๋Š” converter
1
star
43

CoinAPI

'pip install coinapi' - Crypto Currency Data Library
Python
1
star
44

BookCheck-Backend

BookCheck Backend Part
Python
1
star
45

WakeHeart

Java ํ”„๋กœ์ ํŠธ ์„œ๋ฒ„ ์งœ๊ณ  ๋„๋ง๊ฐ€๊ธฐ
Python
1
star
46

Backend

๋ฐฑ์—”๋“œ ์—ญ๋Ÿ‰ ์ฒดํฌ๋ฆฌ์ŠคํŠธ (Backend competency checklist)
1
star
47

minitwit-py

Python + Flask + peewee ORM + JWT powered twitter clone
Python
1
star
48

DMS-Migrates-to-Python

DMS ์„œ๋ฒ„๋ฅผ Python+Flask+MongoDB ๊ธฐ๋ฐ˜์œผ๋กœ ๋งˆ์ด๊ทธ๋ ˆ์ด์…˜
Python
1
star
49

Flask-Serverless

This is how I structure my serverless flask applications using AWS.
Python
1
star
50

minitwit-go

Go + Echo + MongoDB + JWT powered twitter clone
Go
1
star
51

Reflections

'pip install reflections' - Way to list all the modules in a Python package
Python
1
star
52

minecraft-2x-item-mode

๋งˆ์ธํฌ๋ž˜ํ”„ํŠธ ์•„์ดํ…œ 2๋ฐฐ ๋ชจ๋“œ ใ…‹ใ…‹
1
star
53

Flask-restful-autoroute

'pip install flask-restful-autoroute' - Blueprint based auto routing library for flask-restful
Python
1
star
54

DMS-Server-Refactoring

DMS ์„œ๋ฒ„๋ฅผ ๋ฆฌํŒฉํ† ๋งํ•˜์ž
Java
1
star