Created
April 21, 2021 21:09
-
-
Save doobeh/ee0b8b95fbc9539d7695a9788089e9ee to your computer and use it in GitHub Desktop.
creating_database
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
import os | |
from flask import Flask | |
from config import Config | |
from flask_utils import page_bp | |
from db_creation import db | |
def create_app(): | |
appname = "IOT - PROJECT NASTIS" | |
app = Flask(appname) | |
myconfig = Config | |
app.config.from_object(myconfig) | |
app.register_blueprint(page_bp, url_prefix='') | |
db.init_app(app) | |
return app | |
def setup_database(app): | |
with app.app_context(): | |
db.create_all() | |
if __name__ == "__main__": | |
app = create_app() | |
setup_database(app) | |
port = 8000 | |
interface = '0.0.0.0' | |
app.run(host=interface, port=port, debug=True) |
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
class Config(): | |
SQLALCHEMY_DATABASE_URI = "sqlite:///example.sqlite" | |
SQLALCHEMY_ECHO = True |
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
from flask_sqlalchemy import SQLAlchemy | |
db = SQLAlchemy() |
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
from db_creation import db | |
from User import User | |
from flask import Blueprint | |
page_bp = Blueprint("page_bp", __name__) | |
@page_bp.route('/') | |
def register(): | |
return 'foo' |
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
[[source]] | |
name = "pypi" | |
url = "https://pypi.org/simple" | |
verify_ssl = true | |
[dev-packages] | |
[packages] | |
flask = "*" | |
flask-sqlalchemy = "*" | |
[requires] | |
python_version = "3.8" |
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
from db_creation import db | |
class User(db.Model): | |
username = db.Column(db.String(100), primary_key=True) | |
email = db.Column(db.String(100)) | |
password = db.Column(db.String(100)) | |
def __init__(self, username, email, password): | |
self.username = username | |
self.email = email | |
self.password = password |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment