Skip to content

Commit 8c857da

Browse files
committed
Redirect now works. A template has been added.
1 parent fd067d4 commit 8c857da

File tree

3 files changed

+39
-3
lines changed

3 files changed

+39
-3
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
venv
22
*.pyc
3+
*.swp

gist-flask.py

+19-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,28 @@
11
import os
22

3-
from flask import Flask
3+
from flask import Flask, render_template, url_for, redirect, request
44
app = Flask(__name__)
55

6-
@app.route("/")
6+
@app.route('/')
77
def hello():
8-
return "Hello World!"
8+
return render_template('template.html')
9+
10+
@app.route('/user/<username>/')
11+
# Show the gists for an user
12+
def showUserGists(username):
13+
# Llamada a github con el usuario
14+
# Parseo de gists
15+
return "User %s" % username
16+
17+
@app.route('/search', methods=['POST'])
18+
# Redirect to the correct URL
19+
def redirectToUser():
20+
if request.form['username']:
21+
return redirect(url_for('showUserGists', username=request.form['username']))
22+
else:
23+
return 'Error'
924

1025
if __name__ == "__main__":
1126
port = int(os.environ.get('PORT', 5000))
27+
app.debug = True
1228
app.run(host='0.0.0.0', port=port)

templates/template.html

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<!DOCTYPE HTML>
2+
<html lang="es">
3+
4+
<head>
5+
<title>My GitHub Gists</title>
6+
</head>
7+
8+
<body>
9+
10+
<h1>My GitHub Gists</h1>
11+
12+
<form method="POST" action="/search">
13+
<input type="text" name="username" value="" />
14+
<input type="submit" name="submit" value="Buscar" />
15+
</form>
16+
17+
</body>
18+
19+
</html>

0 commit comments

Comments
 (0)