Building Data-Driven Web Apps with Pyramid and SQLAlchemy Transcripts
Chapter: User input and HTML forms
Lecture: Concept: One source of data
Login or
purchase this course
to watch this video and the rest of the course contents.
0:00
Let's review this concept of having just one source of data rather than four or five being passed in from these different sources on request.
0:09
So we saw that if we just create just a few lines of code the simple create function that takes your request and returns this thing we created
0:16
called a request dictionary which is really a fancy dictionary that lets you do sort of arbitrary dynamic access
0:23
into its keys as if they were fields or attributes rather than dictionary style with .get or square brackets and things like that.
0:31
Then what we're going to do is we're going to pass in the request and we're going to say "Let's go and get the query string
0:36
and the headers and the Post and the matchdict and all of that stuff and merge it into one super dictionary." And if there's data that is in both
0:44
like say in the matchdict and the Get the last one wins. So in this case anything in matchdict is going to override anything in the query string.
0:53
And then if we just use this in our action methods it gets so much simpler. So over here in our registered post
1:00
we say create us one of these dictionaries when we say d.email_address d.password where email_address and password
1:07
these were the named input elements in our form. This is certainly an optional design pattern but it's very very useful to help just centralize
1:17
where all this data is coming from.