-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
executable file
·28 lines (22 loc) · 831 Bytes
/
app.py
File metadata and controls
executable file
·28 lines (22 loc) · 831 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from datetime import datetime
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
app = Flask(__name__)
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///db.sqlite3'
db = SQLAlchemy(app)
class User(db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(50))
location = db.Column(db.String(50))
date_created = db.Column(db.DateTime, default=datetime.now)
@app.route("/<name>/<location>")
def index(name,location):
user = User(name=name, location=location)
db.session.add(user)
db.session.commit()
return "<h1> Adicionado novo usuario!</h1>"
@app.route("/<name>")
def get_user(name):
user = User.query.filter_by(name=name).first()
return f'<h1> O usuario se localiza em: {user.location} <h1>'