forked from MarkGao11520/ginger
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
03a18d3
commit d84879e
Showing
26 changed files
with
209 additions
and
243 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,30 @@ | ||
""" | ||
create by gaowenfeng on | ||
""" | ||
from flask import Flask | ||
from flask import Flask as _Flask | ||
from flask.json import JSONEncoder as _JSONEncoder | ||
|
||
from datetime import date | ||
|
||
from app.libs.error_code import ServerError | ||
|
||
__author__ = "gaowenfeng" | ||
|
||
|
||
def register_blueprint(app): | ||
from app.api.v1 import create_blueprint_v1 | ||
app.register_blueprint(create_blueprint_v1(), url_prefix='/v1') | ||
class JSONEncoder(_JSONEncoder): | ||
|
||
def default(self, o): | ||
if hasattr(o, 'keys') and hasattr(o, '__getitem__'): | ||
return dict(o) | ||
# 兼容其他的序列化 | ||
if isinstance(o, date): | ||
return o.strftime('%Y-%m-%d') | ||
raise ServerError() | ||
|
||
|
||
def register_plug(app): | ||
from app.models.base import db | ||
db.init_app(app) | ||
with app.app_context(): | ||
db.create_all() | ||
class Flask(_Flask): | ||
json_encoder = JSONEncoder | ||
|
||
|
||
def create_app(): | ||
app = Flask(__name__) | ||
app.config.from_object('app.config.secure') | ||
app.config.from_object('app.config.setting') | ||
|
||
register_blueprint(app) | ||
register_plug(app) | ||
return app | ||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
""" | ||
create by gaowenfeng on | ||
""" | ||
|
||
__author__ = "gaowenfeng" | ||
|
||
|
||
class Person: | ||
name = 'gwf' | ||
age = 18 | ||
|
||
def __init__(self): | ||
self.gender = 'male' | ||
|
||
def keys(self): | ||
return ('name', 'age', 'gender') | ||
|
||
def __getitem__(self, item): | ||
return getattr(self, item) | ||
|
||
|
||
o = Person() | ||
print(dict(o)) |
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters