Last active
March 6, 2017 11:20
-
-
Save raj454raj/483fcf3db366b3961d31659db32b4b5a to your computer and use it in GitHub Desktop.
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 import * | |
from flask_sqlalchemy import SQLAlchemy | |
app = Flask(__name__) | |
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////tmp/test.db' | |
db = SQLAlchemy(app) | |
class User(db.Model): | |
id = db.Column(db.Integer, primary_key=True) | |
name = db.Column(db.String(80)) | |
email = db.Column(db.String(120)) | |
def __init__(self, name, email): | |
self.name = name | |
self.email = email | |
def __repr__(self): | |
return '<User %r>' % self.name | |
@app.route("/addUser") | |
def add_user(): | |
name = request.args.get("name") | |
email = request.args.get("email") | |
user = User(name, email) | |
db.session.add(user) | |
db.session.commit() | |
return "Successfully added" | |
@app.route("/users") | |
def get_users(): | |
print(User.query.all()) | |
return "All users printed" | |
db.create_all() | |
if __name__ == "__main__": | |
app.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
After running the server -
Open -
http://localhost:5000/addUser?name=Raj&email=raj454raj@gmail.com