"micro" framework...?
https://slides.com/superdiana/flask-pt
$whoami
Diana Rodríguez
Google Developer Expert:
- Web Technologies - Google Maps Platform
- Google Cloud Platform - Firebase
Auth0 Ambassador
Microsoft MVP: Developer Technologies
Python Developer Advocate @ Vonage
🚀 https://superdi.dev
🐦 @cotufa82

Uma pessoa que aprende algo novo todos os dias !!

$whoami-NOT

-
Framework Agnostic
-
Weapon of Choice
-
Zero Wars/Mobs/Cults
-
Exemplos "óbvios"
🛁🧼
Flask
"Flask e um microframework de Python que é baseado em Werkzeug, Jinja 2 e boas intenções. Através do Flask, podemos criar aplicaçoes Web e Restful com Python de uma maneira extremamente simple ".


"Microframework"


Pros!
- Curva de aprendizagem ✅
- "production ready" ✅
- Boa gestão de rotas
- Sessions! ✅
- Extensible ✅
- Excelente documentação ✅
Cons
- Ninguno
- Complexo para aplicaçoes muito grandes
- Comunidade
- Sem admin
- Sem login o auth
- Sem ORM
- Migrações podem ser complicadas


Full
Stack
Flask!?






Rapidinho!
Contexto...



### layout.hmtl
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="{{ url_for('static', filename='css/materialize.min.css') }}">
<link rel="stylesheet" href="{{ url_for('static', filename='css/style.css') }}">
{% block head %}{% endblock %}
</head>
<body>
<header class="container-fluid">
<nav class="teal">
<div class="container">
<div class="row">
<div class="col">
<a href="#" class="brand-logo"><i class="material-icons logo">record_voice_over</i> Scout = Nexmo + Nightscout</a>
</div>
</div>
</div>
</nav>
</header>
<main class="container">
{% block content %}{% endblock %}
</main>
<footer class="page-footer teal">
<div class="footer-copyright">
<div class="container">
Made By <a class="brown-text text-lighten-3">CodeON</a>
</div>
</div>
</footer>
<script language="javascript" src="{{ url_for('static', filename='js/materialize.min.js') }}"></script>
{% block script %}{% endblock %}
</body>
</html>
### login.html
{% extends "layout.html" %}
{% block head %}
<script src="https://apis.google.com/js/platform.js" async defer></script>
<meta name="google-signin-client_id" content="{{ client_id }}">
{% endblock %}
{% block content %}
<div id="user" class="guest">Welcome guest, You need to authenticate</div>
<div class="row">
<div class="col s6 offset-s3">
<div class="card blue-grey darken-1">
<div class="card-content white-text">
<span class="card-title">Login To Enter Scout</span>
<p>This application is going to allow you configure some alerts to your Phone, a Favorite Phone or 5 contact Phones. If you use a nightscout device and you have your api available for external queries. You can use this server and when the glucose level is to low and to high you will receive a call to indicates the glucose level. If you not Answer the call then an sms is sent to your favorite number and other 5 contact numbers.</p>
<div class="g-signin2" data-onsuccess="onSignIn"></div>
</div>
</div>
</div>
</div>
<script language="javascript">
function onSignIn(googleUser) {
var profile = googleUser.getBasicProfile();
if(profile.getId()!==null && profile.getId()!==undefined){
var xhr = new XMLHttpRequest();
xhr.open('POST', '{{ site_url|safe }}/login');
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xhr.onload = function() {
console.log('Signed in as: ' + xhr.responseText);
//Authenticated so redirect to index
window.location = "{{ site_url|safe }}/";
};
xhr.send('idtoken=' + googleUser.getAuthResponse().id_token + "&username=" + profile.getName() + "&email=" + profile.getEmail());
}
}
</script>
### app.py
@app.route('/login',methods=["POST"])
def login():
try:
token = request.form.get("idtoken")
client_id = os.getenv("GOOGLE_CLIENT_ID")
infoid = id_token.verify_oauth2_token(token, google.auth.transport.requests.Request(), client_id)
if infoid['iss'] not in ['accounts.google.com', 'https://accounts.google.com']:
raise ValueError('Wrong issuer.')
userid = infoid['sub']
#Here is a good place to create the session
session["user"] = {"userid": userid, "username": request.form.get("username"), "email": request.form.get("email")}
return userid
except ValueError:
return "Error"
pass


Assim... 🤔
- Flask é apenas para pequenos projetos?
- Por que chamamos micro framework?
- Você pode fazer tudo o que o Django faz?
- Em quais casos devo usar o Flask em vez do Django?
Em conclusão...
- Excelente opção se você está iniciando o desenvolvimento com Python, e se não ... também 😜
- Não se limita ao desenvolvimento de aplicações simples.
- Coloque e decole à vontade e de acordo com necessidades específicas!
- Depois de dominar o Flask, mudar para Django será muito fácil ...
- ... Ou talvez, não seja necessário!

Micro framework?



PRAISE YOURSELF
Resources
MUITO OBRIGADA!!
@cotufa82

https://superdi.dev
Flask: Quão "micro" framework?
By Super Diana
Flask: Quão "micro" framework?
- 832