On 4/15/20 7:24 PM, Gavin Wiener wrote:
Hey Tim
Hello Gavin: Thank you for your prompt reply.
The bigger question is, what are you trying to achieve?
I gotta know. I'm a retired programmer with 19 years doing CGI. Wrote
and implemented my own framework. First in C, than C++ then rebol, then
python.
I really want to know what is going on "under the hood" but I also wish
to know why those examples, taken from documentation do not work.
I'm building a website with django as an alternative to the original in
Drupal because I want fine-grained control.
I hope that answers your question.
With the DetailView, fetching the object with the primary key is
already handled for you, as you've seen the object will already be
available in the template.
This website is very useful to know which functions are implemented in
a class-based view, and which variables are available.
http://ccbv.co.uk/
Thanks for the link. Will study it after finishing my coffee.
On Thursday, April 16, 2020 at 8:26:00 AM UTC+8, tim042849 wrote:
using django.VERSION (2, 1, 5, 'final', 0) with
python 3.7.2 on ubuntu 16.04
Given the URL pattern below:
path('<int:pk>', ArticleDetailView.as_view(), name='article_detail'),
And the view as below:
class ArticleDetailView(DetailView):
model = Article
template_name = 'article_detail.html'
login_url = 'login'
I can access the variable pk from a template as
article.pk <http://article.pk>
But I don't know how to access the pk variable from the view itself.
Adding the get_queryset method to the view doesn't work
example
def get_queryset(self):
print(self.kwargs["pk"])
results in
'NoneType' object has no attribute 'filter' Trying def
get_object(self): queryset =
self.filter_queryset(self.get_queryset()) obj =
queryset.get(pk=self.kwargs['pk']) return obj results in
'ArticleDetailView' object has no attribute 'filter_queryset'
Please advise - pretty basic for django, new to me :) thanks
--
Tim
tj49.com <http://tj49.com>
--
You received this message because you are subscribed to the Google
Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to django-users+unsubscr...@googlegroups.com
<mailto:django-users+unsubscr...@googlegroups.com>.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/39595843-0a01-4ffb-95b9-46d2d3c442e3%40googlegroups.com
<https://groups.google.com/d/msgid/django-users/39595843-0a01-4ffb-95b9-46d2d3c442e3%40googlegroups.com?utm_medium=email&utm_source=footer>.
--
Tim
tj49.com
--
You received this message because you are subscribed to the Google Groups "Django
users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/52390ecd-3748-6c96-3a1b-a2d671322336%40akwebsoft.com.