@@ -42,7 +42,7 @@ In your app's `urls.py` file...
42
42
43
43
urlpatterns = [
44
44
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),
46
46
]
47
47
48
48
### Add the appropriate view function ##
62
62
- `from django.shortcuts import render, get_object_or_404`
63
63
- Get the value from the database and pass it to the view just like we did in current_cats
64
64
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
+
65
99
### Create a template for the detail page ###
66
100
Why: Now that we have a ` Cat ` object, we need a template in which to display its data!
67
101
77
111
- Create and run the migrations
78
112
- Check out [ Django Models] ( ../django_models/README.md ) for a reminder
79
113
- Work these new things into your view!
114
+
115
+ - I added pictures!
116
+
117
+ ![ Kitty!] ( images/crono.png )
0 commit comments