Initial setup

This commit is contained in:
Kian 2024-08-08 10:53:32 -04:00
commit 158d83341b
10 changed files with 85 additions and 0 deletions

4
.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
# Default ignored files
/shelf/
/workspace.xml
.env

3
.idea/.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
# Default ignored files
/shelf/
/workspace.xml

View File

@ -0,0 +1,6 @@
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>

10
.idea/misc.xml Normal file
View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Black">
<option name="sdkName" value="zl-back" />
</component>
<component name="ProjectRootManager" version="2" project-jdk-name="zl-back" project-jdk-type="Python SDK" />
<component name="PyCharmProfessionalAdvertiser">
<option name="shown" value="true" />
</component>
</project>

8
.idea/modules.xml Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/zl-back.iml" filepath="$PROJECT_DIR$/.idea/zl-back.iml" />
</modules>
</component>
</project>

6
.idea/vcs.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

8
.idea/zl-back.iml Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="jdk" jdkName="zl-back" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

17
main.py Normal file
View File

@ -0,0 +1,17 @@
import os
from dotenv import load_dotenv
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from routes import register_route
load_dotenv()
db = SQLAlchemy()
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = os.getenv("SQLALCHEMY_DATABASE_URI")
db.init_app(app)
register_route(app, db)
if __name__ == '__main__':
app.run(debug=True)

0
models.py Normal file
View File

23
routes.py Normal file
View File

@ -0,0 +1,23 @@
import os
from flask import jsonify
from sqlalchemy import inspect
def register_route(app,db):
@app.route("/")
def hello_world():
return "<p>Hello, World!</p>"
@app.route('/user/')
@app.route('/user/<username>')
def show_user_profile(username=None):
test = os.getenv("MY_KEY")
if username:
return f"<p>Hello, Mr {username}! You are the man.</p> {test}"
return "<p>Hello, user!</p>"
@app.route('/table')
def list_table():
inspector = inspect(db.engine)
tables = inspector.get_table_names()
return jsonify(tables)