I\'m new to Flask, and having some issues setting up a very basic Flask app. Right now, I\'m trying to get the user to submit a form on the homepage and then save that form to
Create a model in models.py:
from __init__.py import db
class ContactModel(db.Model):
__tablename__ = 'contact'
id = db.Column(db.Integer, primary_key = True)
name = db.Column(db.String(120))
email = db.Column(db.String(120))
def save_to_db(self):
db.session.add(self)
db.session.commit()
Then in init.py:
from flask import Flask
from config import Config
from flask_sqlalchemy import SQLAlchemy
from flask_migrate import Migrate
app = Flask(__name__)
app.config.from_object(Config)
db = SQLAlchemy(app)
migrate = Migrate(app, db)
#create all db tables
@app.before_first_request
def create_tables():
from models import ContactModel
db.create_all()
from app import routes, models