Commit fd4f5fd1 authored by Ernesto Crespo's avatar Ernesto Crespo

Articulo 2

parent 20dcb30a
__pycache__/
......@@ -2,4 +2,3 @@ from flask import Flask
app = Flask(__name__)
from app import views
<html>
<head>
{% if title %}
<title>{{ title }} - microblog</title>
{% else %}
<title>microblog</title>
{% endif %}
</head>
<body>
<div>Microblog: <a href="/index">Home</a></div>
<hr>
{% block content %}{% endblock %}
</body>
</html>
{% extends "base.html" %}
{% block content %}
<h1>Hola, {{ usuario.nickname }}!</h1>
{% for post in posts %}
<p>
{{ post.autor.nickname }} dice: <b>{{ post.cuerpo }}</b>
</p>
{% endfor %}
{% endblock %}
#!/usr/bin/env python
#Se importa render_template para renderizar plantillas html
from flask import render_template
#Se importa la aplicacion
from app import app
@app.route('/<nombre>')
def hola_nombre(nombre):
return "Hola {}!".format(nombre)
#Se define la ruta del url raiz e index
@app.route('/')
def hola():
return "Hola mundo!"
@app.route('/index')
def index():
#Se define el nombre del usuario
usuario = {'nickname': 'Ernesto'}
#Se define los posts del blog
posts = [
{
'autor': {'nickname': 'John Doe'},
'cuerpo': 'Un dia en Edimburgo'
},
{
'autor': {'nickname': 'Jane Doe'},
'cuerpo': 'Muy buena Civil war!'
}
]
#Se devuelve index.html con el titulo, usuario y posts
return render_template("index.html",
title='Home',
usuario=usuario,
posts=posts)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment