One thing I discovered is that I had the line for the url.py file in my top level url.py. I moved it to myapp/url.p but still same 404 error, however no longer get the "has no attribute" error
How do I call this view? Tried from the browser "http://127.0.0.1:8000/today/" and I get "__init__() takes 1 positional argument but 2 were given" error.
Tried "http://127.0.0.1:8000/visit/today/" and I get 404 error.
In the line "queryset = Visit.objects.all()" won't that select all of the records in the database when I only want the records for today which I then use to create a reportlab pdf file? Prior to trying to use these generic date views I was able to generate the file but only for the current date.
Are there any more suggestions?
TIA...
On Wed, Aug 08, 2018 at 05:42:06AM -0700, Gerald Brown wrote:On Wednesday, August 8, 2018 at 8:15:21 PM UTC+8, Jason wrote:what have you tried so far? What issues are you having with the documentation examples? "can't get them to work" is really uninformative, RIGHT.What I tried was the TodayArchiveView by following the docs. When I enter http://127.0.0.1:8000/admin/visit/today/ in my browser I get a 404 error The code in my views.py file is: class PaymentTodayArchiveView(TodayArchiveView): This is exactly as it is in my code and also in the docs except I changed Article to Payment. vi = Visit.objects.all() I changed vi to queryset and it made NO difference. date_field = "visit_date" The code in my URLS.py file is: path('today/', PaymentTodayArchiveView, name="today"), In the docs is says ".as_view()" should be added to PaymentTodayArchiveView. When I add that I get "AttributeError: 'function' object has no attribute 'as_view'" error.This exception indicates that you didn't define PaymentTodayArchiveView as a class, but rather as a function (which is not consistent with the code you pasted above). As long as PaymentTodayArchiveView is defined as a subclass of TodayArchiveView, like in your snippet, you should be able to call ``as_view`` on it. So yes, using ``PaymentTodayArchiveView.as_view()`` in your URL config would be correct, as long as the definition of PaymentTodayArchiveView is correct. And regarding the name (``queryset`` vs. ``vi``) – the point of using generic views is that the default implementation of the view supplies most functionality. Most of the time, you're able to configure what objects the view operates on by setting certain class attributes in your customized subclasses. In this case, all of the generic date views by default look at the ``queryset`` class attribute when they want to read objects from the database, not ``vi``, which is why you'd typically use that name in your subclass. Good luck, Michal
No comments:
Post a Comment