from flask import Flask,render_template,request
from flask_sqlalchemy import SQLAlchemy
app=Flask(__name__)
app.config['SQLALCHEMY DATAVASE URI']='mysql://root:@localhost/mk_gupta'
db = SQLAlchemy(app)
class Contacts(db.Model):
Serial_no = db.Column(db.Integer, primary_key=True)
Name=db.Column(db.String(40),unique=False,nullable=False)
Email=db.Column(db.String(40),unique=False,nullable=False)
Subject=db.Column(db.String(100),unique=False,nullable=True)
Message=db.Column(db.String(500),unique=False,nullable=False)
@app.route("/",methods=['GET','POST'])
def home():
if (request.method == 'POST'):
'''Add entry to the database'''
name=request.form.get('name')
email=request.form.get('email')
subject=request.form.get('subject')
message=request.form.get('message')
entry=Contacts(Name=name,Email=email,Subject=subject,Message=message)
db.create_all()
db.session.add(entry)
db.session.commit()
db.session.close()
return render_template('index.html')
if __name__ =='__main__':
app.run(debug=True)
--
SQLAlchemy -
The Python SQL Toolkit and Object Relational Mapper
http://www.sqlalchemy.org/
To post example code, please provide an MCVE: Minimal, Complete, and Verifiable
Example. See http://stackoverflow.com/help/mcve for a full description.
---
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/sqlalchemy/fc20db78-f150-488a-9ce1-86eee5c7e89an%40googlegroups.com.