Following on from the previous allauth, I have now created a calendar and booking function. I’m getting used to the errors and want to learn to look for error points.
- 1 First stumbling point
- 2 The “0” mark or “hyphen (-)” that should have been set in the calendar is not displayed.
- 3 Fixed NoReverseMatch at.
- 4 AttributeError: ‘Booking’ object has no attribute…
- 5 Side note: What is “make_aware”?
- 6 Side trip 2: What is timedelta?
- 7 Recommend
- First stumbling point
First stumbling point
The QuerySet value for an exact lookup must be limited to one result using slicing.
Zero  was missing from the code, so I added it and it displayed well.
The “0” mark or “hyphen (-)” that should have been set in the calendar is not displayed.
The first thing I checked was the font-awesome link setting and the icon description error. There were no mistakes here.
In the for statement on line 55, “items” was “iems”. This was a common spelling error for beginners. After correction, it was displayed properly.
Fixed NoReverseMatch at.
Reverse for 'teacher' not found. 'teacher' is not a valid view function or pattern name. <Cause> I forgot the 'name' I had named myself and called a different 'name'.
Before correction：return redirect(‘teacher’)
After modification: return redirect(‘staff’) successfully displayed the page.
PS: I want to transition to the reservation completion page, so I ended up calling “‘thanks’ (reservation completion screen)”.
AttributeError: ‘Booking’ object has no attribute…
A common spelling mistake for beginners. This time, I found a mistake in Booking in models.py!
I found a site that has a good summary of countermeasures for each error message: Click Here
If you read the error message carefully, it says that “first_name” is missing from “Booking,” so you can find it by going straight to models.py where you set up the “Booking” class, but as a beginner, I get impatient when I see the yellow screen with that error.
Side note: What is “make_aware”?
NAIVE and AWARE (with or without time zone)
The same datetime object can have either a time zone or no time zone.
In Python, a datetime with a time zone is called an aware date/time and a datetime without a time zone is called a naive date/time.
It seems that if you don’t set the model (database) to use either naive or aware, the time system will error out.
The problem is not in Django settings, but in the date passed to the model. Here’s how a timezone-aware object looks like:
>>> from django.utils import timezone
>>> import pytz
datetime.datetime(2013, 11, 20, 20, 8, 7, 127325, tzinfo=pytz.UTC)
And here’s a naive object:
>>> from datetime import datetime
datetime.datetime(2013, 11, 20, 20, 9, 26, 423063)Reference: stackflowのリンクはコチラ
Side trip 2: What is timedelta?
I didn’t study python well and started Django as a beginner, so there are many points to be tripped up. the word “timedelta” that came up in views.py bothered me, so I’m going to look it up.
class datetime.timedelta(days=0, seconds=0, microseconds=0, milliseconds=0, minutes=0, hours=0, weeks=0)
The default value of all arguments is zero and all are optional.iQueryAZ
The “timedelta” is also frequently used in this reservation system. It seems to be used when we want to specify the starting position or initial value of a date or time, so let’s study it more carefully.