Skip to content

Commit 6d3e657

Browse files
committed
Cleanup code formatting in spanish version a bit
1 parent ffbcdf8 commit 6d3e657

File tree

1 file changed

+43
-50
lines changed

1 file changed

+43
-50
lines changed

es/extend_your_application/README.md

Lines changed: 43 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,26 @@ Ya tenemos un modelo `Post`, así que no necesitamos añadir nada a `models.py`.
1111
## Crea un enlace en la plantilla
1212

1313
Vamos a empezar añadiendo un enlace dentro del archivo `blog/templates/blog/post_list.html`. Hasta el momento debería verse así:
14-
``` html
15-
{% extends 'blog/base.html' %}
16-
17-
{% block content %}
18-
{% for post in posts %}
19-
<div class="post">
20-
<div class="date">
21-
{{ post.published_date }}
22-
</div>
23-
<h1><a href="">{{ post.title }}</a></h1>
24-
<p>{{ post.text|linebreaksbr }}</p>
14+
```html
15+
{% extends 'blog/base.html' %}
16+
17+
{% block content %}
18+
{% for post in posts %}
19+
<div class="post">
20+
<div class="date">
21+
{{ post.published_date }}
2522
</div>
26-
{% endfor %}
27-
{% endblock %}
23+
<h1><a href="">{{ post.title }}</a></h1>
24+
<p>{{ post.text|linebreaksbr }}</p>
25+
</div>
26+
{% endfor %}
27+
{% endblock %}
2828
```
2929

3030
Queremos tener un enlace a una página de detalle sobre el título del post. Vamos a cambiar `<h1><a href="">{{ post.title }}</a></h1>` dentro del enlace:
3131
```
32-
<h1><a href="proxy.php?url=https%3A%2F%2Fgithub.com.%2F%7B%25+url+%27post_detail%27+pk%3Dpost.pk+%25%7D">{{ post.title }}</a></h1>
33-
```
32+
<h1><a href="proxy.php?url=https%3A%2F%2Fgithub.com.%2F%7B%25+url+%27post_detail%27+pk%3Dpost.pk+%25%7D">{{ post.title }}</a></h1>
33+
```
3434

3535
Es hora de explicar el misterioso `{% url 'post_detail' pk=post.pk %}`. Como probablemente sospeches, la notación `{% %}` significa que estamos utilizando Django template tags. ¡Esta vez vamos a utilizar uno que va a crear una dirección URL para nosotros!
3636

@@ -48,7 +48,7 @@ Ahora cuando vayamos a: http://127.0.0.1:8000/ tendremos un error (como era de e
4848

4949
Queremos crear una URL que apunte a Django a una *view* denominada `post_detail`, que mostrará una entrada del blog. Agrega la línea `url (r'^post/(?P<pk>[0-9]+)/$', views.post_detail),` al archivo `blog/urls.py`. Debería tener este aspecto:
5050

51-
``` python
51+
```python
5252
from django.conf.urls import url
5353
from . import views
5454

@@ -84,10 +84,8 @@ Esta vez nuestra *view* tomará un parámetro adicional `pk`. Nuestra *view* nec
8484

8585
Ahora, queremos sólo un post del blog. Para ello podemos usar querysets como este:
8686

87-
``` python
88-
89-
Post.objects.get(pk=pk)
90-
87+
```python
88+
Post.objects.get(pk=pk)
9189
```
9290

9391
Pero este código tiene un problema. Si no hay ningún `Post` con `llave primaria` (`pk`) tendremos un error muy feo.
@@ -109,19 +107,16 @@ La buena noticia es que puedes crear tu propia página `Page Not Found` y diseñ
109107
Deberíamos abrir `blog/views.py` y agregar el siguiente código:
110108

111109
```python
112-
113-
from django.shortcuts import render, get_object_or_404
114-
110+
from django.shortcuts import render, get_object_or_404
115111
```
116112

117113
Cerca de otras líneas `from`. Y en el final del archivo añadimos nuestra *view*:
118114

119115
```python
120116
def post_detail(request, pk):
121-
    post = get_object_or_404(Post, pk=pk)
122-
    return render(request, 'blog/post_detail.html', {'post': post})
123-
124-
```
117+
post = get_object_or_404(Post, pk=pk)
118+
return render(request, 'blog/post_detail.html', {'post': post})
119+
```
125120

126121
Sí. Es hora de actualizar la página: http://127.0.0.1:8000/
127122

@@ -142,19 +137,19 @@ Crearemos un archivo en `blog/templates/blog` llamado `post_detail.html`.
142137
Se verá así:
143138

144139
```html
145-
{% extends 'blog/base.html' %}
146-
147-
{% block content %}
148-
    <div class="post">
149-
        {% if post.published_date %}
150-
            <div class="date">
151-
                {{ post.published_date }}
152-
            </div>
153-
        {% endif %}
154-
        <h1>{{ post.title }}</h1>
155-
        <p>{{ post.text|linebreaksbr }}</p>
156-
    </div>
157-
{% endblock %}
140+
{% extends 'blog/base.html' %}
141+
142+
{% block content %}
143+
    <div class="post">
144+
        {% if post.published_date %}
145+
            <div class="date">
146+
                {{ post.published_date }}
147+
            </div>
148+
        {% endif %}
149+
        <h1>{{ post.title }}</h1>
150+
        <p>{{ post.text|linebreaksbr }}</p>
151+
    </div>
152+
{% endblock %}
158153
```
159154

160155
Una vez más estamos extendiendo `base.html`. En el bloque `content` queremos mostrar la fecha de publicación (si existe), título y texto de nuestros posts. Pero deberíamos discutir algunas cosas importantes, ¿cierto?
@@ -174,20 +169,18 @@ Bien, podemos actualizar nuestra página y ver si `Page Not Found` se ha ido.
174169
Sería bueno verificar que tu sitio web aún funcionará en PythonAnywhere, ¿cierto? Intentemos desplegar de nuevo.
175170

176171
```
177-
178-
$ git status
179-
$ git add --all .
180-
$ git status
181-
$ git commit -m "Added views to create/edit blog post inside the site."
182-
$ git push
183-
184-
```
172+
$ git status
173+
$ git add --all .
174+
$ git status
175+
$ git commit -m "Added views to create/edit blog post inside the site."
176+
$ git push
177+
```
185178

186179
* Luego, en una [consola Bash de PythonAnywhere][8]
187180

188181
```
189-
$ cd my-first-blog
190-
$ git pull [...]
182+
$ cd my-first-blog
183+
$ git pull [...]
191184
```
192185

193186
* Finalmente, ve a la pestaña [Web][9] y haz click en **Reload**.

0 commit comments

Comments
 (0)