-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
53 lines (48 loc) · 1.73 KB
/
app.py
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
from flask import Flask, request, jsonify, render_template
app = Flask(__name__)
# Rota para a página inicial
@app.route('charada.html')
def index():
return '''
<!DOCTYPE html>
<html>
<head>
<title>Charada</title>
</head>
<body>
<h2>Resolva a Charada!</h2>
<form id="charadaForm">
<label for="resposta">Insira sua resposta:</label>
<input type="text" id="resposta" name="resposta">
<button type="submit">Enviar Resposta</button>
</form>
<script>
document.getElementById('charadaForm').onsubmit = async function(e) {
e.preventDefault();
const resposta = document.getElementById('resposta').value;
const response = await fetch('/enviar-resposta', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({resposta: resposta})
});
if (response.ok) {
alert('Resposta enviada com sucesso!');
} else {
alert('Erro ao enviar resposta.');
}
}
</script>
</body>
</html>
'''
# Endpoint para processar a resposta
@app.route('/enviar-resposta', methods=['POST'])
def receber_resposta():
dados = request.json
resposta = dados.get('resposta')
print(f"Resposta recebida: {resposta}")
return jsonify({'mensagem': 'Resposta recebida com sucesso!'}), 200
if __name__ == '__main__':
app.run(debug=True)