PyCon 2014

Desarrollando extensiones para Flask

Rachel Sanders  · 

Presentación

Vídeo

Transcripción

Extracto de la transcripción automática del vídeo realizada por YouTube.

okay good morning everybody and our first talk of the day is developing plastic extensions by rachelsanders she's a developer at LinkedIn and is an organizer of the PI ladies in San Francisco so please give her a warm welcome hello everybody I want to

apologize in advance for my voice I have caught the con flu so I will try my best not to sneeze and death and all of you but I'll just I'll try to give you a warning so there we go anyway welcome thank you so much for coming welcome to developing flask

extensions before we get started a little bit about me I am a pilot a San Francisco organizer organizer and founder and when I'm not doing that I'm an engineer and technical lead at LinkedIn and at LinkedIn I code in Python all day every day and that's

because linkedin's internal stack is Python Python and flask it to be specific oh yes so this talk came out of something I did at work for my team I needed to write an extension for them and I really struggled with getting something a reasonable together

because there's not a lot of documentation out there on writing extensions and doing this kind of work so it turns out that flask is designed to be extended and it's actually I think very very straightforward and so that's my goal of this talk

for you all the walk out of here thinking that extension development is just as straightforward and easy as I think it is okay so we're going to talk about we're going to do a really really quick introduction for those of you who haven't worked

with flask or aren't familiar with it I promise it'll be very quick it'll be like two minutes long and we'll talk about what it means to extend flasks but we're gonna spend most of the talk on a case study on this extension that I wrote

so and we'll talk about how it works in the implementation of it it's a very simple extension it was like 100 lines of code and I've condensed it down to it quite a bit so once we see that very basic extension we're going to talk about where

you can go from there for non-trivial examples for non you know that kind of thing so we'll go sort of like a study of other extensions that are good to learn from what I think and then finally we'll end with questions ok so I thought of a number of

ways to do an introduction to this and the best way I could come up with was just to show you a working flask application this is a working flask application if you pip install flask and run this in a file what you'll get is a dev server running on port

5000 that if you load localhost 5000 in your browser what you'll get is the words hello sandy MS hi print it there and okay so if you're coming from like the Django or rails world you'll look at this and go that's great it's a nice hello

world function ok where's the rest of it where's where's my database where are my forms where is my admin interface and last doesn't have any of those it is a micro framework and this is pretty much what you get you get routes you get controllers

it ships with the templating language ginger it has some session and cookie stuff but what you see in the slide is pretty much what you get and that's actually on purpose because the idea of flask is to build a good foundation for all applications everything

else is up to you or extensions and this is Armen who is the creator of flask laughs is it hearty toolkit you use it to build HTTP things and the core library is purposely kept very small and focused to be good at doing that and that means that most of the

stuff you need as a day-to-day application developer is all in the extension ecosystem so learning how to write extensions is a key part of learning how to write flask ok so let's talk about what it means to extend flask so this is the same hello san dimas

hi application and the slide weren't really bought went by really fast a minute ago but if you look at line 3 that app equals flask name it's actually doing an awful lot so we use a method on it called route to map the route URL to that hello function

and I don't know if you've ever had to do any CGI programming which I had to do back in my bad old Perl days but those three lines of code are lighting over a ton of magic or doing inbound routing it we have some string that were somehow transmitting

into like an HTTP response and so there's a lot of stuff going on there and in the last one we're actually kicking off an entire dev test server so the takeaway is app is the heart of flap that app magic app object which I'm going to call it is

that is where all of the functionality and what flask is so it is the core and when we talk about extending flask what we're really talking about is changing that app object and modifying it like I said flask is designed to be extended and you can change

[ ... ]

Nota: se han omitido las otras 2.411 palabras de la transcripción completa para cumplir con las normas de «uso razonable» de YouTube.