Skip to content

Commit 9f511dd

Browse files
start
1 parent 2d56ab9 commit 9f511dd

File tree

10 files changed

+150
-1
lines changed

10 files changed

+150
-1
lines changed

README.md

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,41 @@
1-
# web-python-flask
1+
# Web Python Flask
2+
3+
Flask es un marco web de Python que proporciona herramientas y funciones útiles para la creación de aplicaciones web en Python. Flask no fuerza una estructura de directorio concreta ni requiere código estándar complicado antes de iniciarse.
4+
5+
## Empezar desde cero
6+
<pre>
7+
python -m venv env
8+
./env/Scripts/activate
9+
python -m pip install --upgrade pip
10+
pip install flask
11+
pip freeze > requirements.txt
12+
flask run --debug
13+
</pre>
14+
15+
## Cargar un proyecto ya construido
16+
<pre>
17+
python -m venv env
18+
./env/Scripts/activate
19+
python -m pip install --upgrade pip
20+
pip install -r requirements.txt
21+
flask run --debug
22+
</pre>
23+
24+
25+
Una vez configurado te aparece:
26+
27+
28+
![alt text](./images/image.png)
29+
30+
31+
visitas la página en el navegador.
32+
33+
34+
![alt text](./images/image-1.png)
35+
36+
37+
Te debe aparecer como sigue:
38+
39+
40+
![alt text](./images/image-2.png)
41+

app.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import json
2+
from flask import Flask, render_template
3+
app = Flask(__name__)
4+
5+
@app.route('/')
6+
@app.route('/<name>')
7+
def hello(name=None):
8+
fileData = open(file="./data/data.json", mode="r", encoding='utf-8')
9+
data = fileData.read()
10+
fileData.close()
11+
response = render_template(
12+
'index.html',
13+
name=name,
14+
items=json.loads(data)
15+
)
16+
return response

data/data.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[
2+
{
3+
"id": "1",
4+
"name": "Oscar Ivan",
5+
"lastname": "Gonzalez",
6+
"email": "oigonzalezp2024@gmail.com",
7+
"phone": "3134563202"
8+
},
9+
{
10+
"id": "1",
11+
"name": "Martha",
12+
"lastname": "Peña",
13+
"email": "marthapp@gmail.com",
14+
"phone": "3224563202"
15+
}
16+
]

images/image-1.png

21.2 KB
Loading

images/image-2.png

39.2 KB
Loading

images/image.png

55.1 KB
Loading

requirements.txt

350 Bytes
Binary file not shown.

static/style.css

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#customers {
2+
font-family: Arial, Helvetica, sans-serif;
3+
border-collapse: collapse;
4+
width: 100%;
5+
}
6+
7+
#customers td, #customers th {
8+
border: 1px solid #ddd;
9+
padding: 8px;
10+
}
11+
12+
#customers tr:nth-child(even){background-color: #f2f2f2;}
13+
14+
#customers tr:hover {background-color: #ddd;}
15+
16+
#customers th {
17+
padding-top: 12px;
18+
padding-bottom: 12px;
19+
text-align: left;
20+
background-color: #04AA6D;
21+
color: white;
22+
}

templates/hello.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<!doctype html>
2+
<title>Hello from Flask</title>
3+
{% if name %}
4+
<h1>Hello {{ name }}!</h1>
5+
{% else %}
6+
<h1>Hello, World!</h1>
7+
{% endif %}

templates/index.html

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="UTF-8">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
{% if name %}
8+
<title>{{ name }}</title>
9+
{% else %}
10+
<title>Proyecto en desarrollo</title>
11+
{% endif %}
12+
<link rel="stylesheet" href="./static/style.css">
13+
</head>
14+
15+
<body>
16+
{% if name %}
17+
<h1>{{ name }}</h1>
18+
{% else %}
19+
<h1>Proyecto en desarrollo</h1>
20+
{% endif %}
21+
<table id="customers">
22+
<thead>
23+
<tr>
24+
<th>id</th>
25+
<th>name</th>
26+
<th>lastname</th>
27+
<th>phone</th>
28+
<th>email</th>
29+
</tr>
30+
</thead>
31+
<tbody>
32+
{%- for row in items|batch(1, '&nbsp;') %}
33+
<tr>
34+
{%- for column in row %}
35+
<td>{{ column.id }}</td>
36+
<td>{{ column.name }}</td>
37+
<td>{{ column.lastname }}</td>
38+
<td>{{ column.phone }}</td>
39+
<td>{{ column.email }}</td>
40+
{%- endfor %}
41+
<tr>
42+
{%- endfor %}
43+
</tbody>
44+
</table>
45+
46+
</body>
47+
48+
</html>

0 commit comments

Comments
 (0)