File tree 10 files changed +89
-0
lines changed
10 files changed +89
-0
lines changed Original file line number Diff line number Diff line change
1
+ from flask import Flask
2
+
3
+ from flask_pymongo import PyMongo
4
+
5
+
6
+ mongo = PyMongo ()
7
+
8
+ def create_app (config_filename = None ):
9
+ application = Flask (__name__ , instance_relative_config = True )
10
+ application .config .from_pyfile (config_filename )
11
+ initialize_extensions (application )
12
+ register_blueprints (application )
13
+ return application
14
+
15
+ def initialize_extensions (application ):
16
+ mongo .init_app (application )
17
+ from app .models .user import User
18
+
19
+
20
+ def register_blueprints (application ):
21
+ from app .controllers import users_blueprint
22
+
23
+ application .register_blueprint (users_blueprint )
24
+
25
+
Original file line number Diff line number Diff line change
1
+ from flask import Blueprint
2
+
3
+ users_blueprint = Blueprint ('users' , __name__ )
4
+ from . import users_controller
Original file line number Diff line number Diff line change
1
+ from flask import request , jsonify
2
+
3
+ from . import users_blueprint
4
+ from app .models .user import User
5
+ from app import mongo
6
+
7
+
8
+ @users_blueprint .route ('/users' )
9
+ def get_users ():
10
+ users = User .get ()
11
+ return jsonify ({'data' : users })
Original file line number Diff line number Diff line change
1
+ from app import mongo
2
+
3
+ class User ():
4
+
5
+ @classmethod
6
+ def get (self ):
7
+ users = mongo .db .users .find ()
8
+ user_list = []
9
+ for user in users :
10
+ data = {}
11
+ data ['first_name' ] = user ['first_name' ]
12
+ data ['last_name' ] = user ['last_name' ]
13
+ user_list .append (data )
14
+ return user_list
15
+
Original file line number Diff line number Diff line change
1
+ python3 test.py
Original file line number Diff line number Diff line change
1
+ # #########################################################
2
+ #
3
+ # This is a sample flask.cfg for developing a Flask application
4
+ #
5
+ # #########################################################
6
+ import os
7
+
8
+
9
+ # Get the folder of the top-level directory of this project
10
+ BASEDIR = os.path.abspath(os.path.dirname(__file__))
11
+
12
+ # Update later by using a random number generator and moving
13
+ # the actual key outside of the source code under version control
14
+ SECRET_KEY = ' bad_secret_key'
15
+ WTF_CSRF_ENABLED = True
16
+ DEBUG = True
17
+
18
+ # SQLAlchemy
19
+ SQLALCHEMY_DATABASE_URI = ' sqlite:///' + os.path.join(BASEDIR, ' app.db' )
20
+ SQLALCHEMY_TRACK_MODIFICATIONS = False
21
+
22
+ # Bcrypt algorithm hashing rounds
23
+ BCRYPT_LOG_ROUNDS = 15
24
+
Original file line number Diff line number Diff line change
1
+ import os
2
+
3
+ yourpath = os .path .abspath (os .path .dirname (__file__ ))
4
+ print (os .path .abspath (os .path .dirname (__file__ )))
5
+ print (os .path .abspath (os .path .join (os .path .abspath (os .path .dirname (__file__ )), os .pardir )))
Original file line number Diff line number Diff line change
1
+ from app import create_app
2
+
3
+ application = create_app ('development.cfg' )
Original file line number Diff line number Diff line change
1
+ print ('Hello Flask' )
You can’t perform that action at this time.
0 commit comments