Skip to content

Commit bc890a2

Browse files
committed
Merge branch 'master' of https://github.com/k0d3k1ttn/tutorial
2 parents 622e555 + 7ac4bcf commit bc890a2

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

en/django_review/README.md

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ In your app's `urls.py` file...
4242

4343
urlpatterns = [
4444
url(r'^$', views.current_cats),
45-
url(r'^kitty/(?P<pk>[0-9]+/$'), views.cat_detail),
45+
url(r'^kitty/(?P<pk>[0-9]+)/$', views.cat_detail),
4646
]
4747

4848
### Add the appropriate view function ##
@@ -62,6 +62,40 @@ How:
6262
- `from django.shortcuts import render, get_object_or_404`
6363
- Get the value from the database and pass it to the view just like we did in current_cats
6464

65+
*Example*
66+
67+
def cat_details(request, pk):
68+
cat = get_object_or_404(Cat, pk=pk)
69+
return render(request, 'kitty/cat_detail.html', {'cat': cat})
70+
71+
- Your detail view might look something like this:
72+
73+
*Example*
74+
75+
<html>
76+
<head>
77+
<title>Kitty Kastle</title>
78+
</head>
79+
<body>
80+
<div>
81+
<h1><a href="">{{ cat.name }}</a></h1>
82+
</div>
83+
84+
<div>
85+
<p>Age: {{ cat.age }}</p>
86+
<p>Color: {{ cat.color }}</p>
87+
<p>Fluffy:
88+
{% if cat.fluffy %}
89+
OMG SO FLUFFY!
90+
{% else %}
91+
Nah
92+
{% endif %}</p>
93+
<p>{{ cat.desc|linebreaks}}</p>
94+
</div>
95+
</body>
96+
</html>
97+
98+
6599
### Create a template for the detail page ###
66100
Why: Now that we have a `Cat` object, we need a template in which to display its data!
67101

@@ -77,3 +111,7 @@ How:
77111
- Create and run the migrations
78112
- Check out [Django Models](../django_models/README.md) for a reminder
79113
- Work these new things into your view!
114+
115+
- I added pictures!
116+
117+
![Kitty!](images/crono.png)

0 commit comments

Comments
 (0)