Developing Websites from Scratch using Python and Django -Part 1 (HD)

All right, well, good morning, good afternoon, good evening, depending on where in the world you happen to be This is Building Websites using Django

That's Susan Ibach I'm Christopher Harrison, and this is actually our kind of cool little desk We're actually a little bit more elevated here >> I feel taller >> It's a little bit interesting

You might actually see us standing and walking around, really just more to upset our studio guy more than any other real technical reason >> Keep him on his toes >> Exactly So here's what's going to happen, is we're going to go ahead and introduce ourselves We'll talk a little bit about MVA

We'll talk a little bit about the course, and then we'll get right on into Django, because we have a fair amount that we want to try and get through today So, Susan, why don't you go ahead and introduce yourself >> Sure So my name is Susan Ibach I'm a Technical Evangelist in Microsoft Canada, and my job is basically to help developers understand how to use different tools that we have at Microsoft for coding, such as Visual Studio

That includes things like app building, as well as web development, which is what we're going to be doing today My background is I was, and still am, a Microsoft certified trainer, so I spend a lot of time showing people how to code, and the first program I ever wrote was actually written in Basic on a computer with 64K of memory, because why would anyone need more than 64K of memory? That's the real question So yeah, that's little bit about me >> Excellent I am Christopher Harrison

I'm a content developer here, or Senior Content Developer There we go But anyway, here at Microsoft Learning I'm a long-time Microsoft Certified Trainer I was a full-time MCT for around about 14, 15 years, so teaching a lot of people different technology

Actually, it was a year ago, 15 days ago, actually, that I actually got started here at Microsoft Still miss my Commodore 64 I present at TechEd, Ignite, and I'm a marathoner, husband and father of one four-legged child Now, as far as what I'm going to wind up covering today, there's the basic outlook for developing websites with Django and Python Now, one big thing that I want to do right up front before I kind of walk through those six modules is sort of set a little bit of expectations

Because we've got roughly about 55 hours if you account for breaks and things like that of actual content or actual time here, which in turn is the amount of content that we're going to be able to cover Our goal is not to try and cover everything about Django, and in fact, there's a couple of different things we'll get into, like building forms, like using the ORM, that we could spend really three, four hours trying to dig into So our real goal here today is to give you everything that you need to get going in doing your development in Django and hopefully kind of give you that jump start, if you will, to give you that head start into getting out and digging in from there >> Yeah, because, basically you'll have an understanding of that framework, the pieces of the puzzle that make Django work and how to make each of those pieces sort of fit together

>> Exactly >> And then you can, of course, take it too much further than we'll get into today >> Exactly, yes So the basic outline looks a little bit like this You'll notice, Module 1, kind of the ubiquitous introduction to Django

We'll do Hello World, because we're required to by law, so we'll go ahead and do that And then Module 2, we'll take a look at models and databases, see how we're going to store our data on the back end and how we're actually going to represent that in code, and then also in turn in Module 3 how we can take data, put it into the database and then eventually pull it back out of the database >> Right, and then we'll get into things like routing, so how do we control where is somebody going to go, based on the URLs they've typed in, because that's going to be essential, working with websites >> Absolutely We'll take a look at how to handle bot layouts and forms, so how we can use the templating system that Django provides and the form system that Django provides, which is really, really cool, and then we'll close it all off with deployment and what I've generically called next steps, which is basically, here's some stuff we want to talk about that didn't fit into any of the other modules, so we'll just put it at the last one, which is sort of always what happens there

Now, as far as expectations, we expect that you have some level of experience with Python However, if you haven't done Python, one of the things that you're going to notice about Python is it's a relatively easy language to pick up if you've done another programming language So if you're familiar with Basic, VB, if you're familiar with C#, taking a look and seeing what Python does is pretty straightforward Obviously, there's some differences There's some little things that might kind of throw you a little bit for a loop, for example, like on if statements and blocks, you tab in, while in C# you've got curly braces or you've got if and end if in VB, but it's still pretty easy to pick up

So if you're maybe a C# developer doing MVC, and you really just want to see, okay, well what other platforms are out there, this is a perfect place to check out Now, as far as the prerequisites then, like we said, some Python experience, some MVC If you've done Flask, that's awesome You'll actually notice there's a lot of commonality between what we saw with Flask and what we're going to wind up seeing today, and if you really want to get in and see programming with Python, see more of Susan and I and hear a lot more bad jokes, then you can check out the introduction to programming with Python MVA Speaking of MVA, there is an MVA community

I really need to update this slide like horribly, now I want to say we actually did in fact cross the 4 million registered users, or at the very least, we're at like three and change million registered users, so a pretty sizable community there So all of this free online learning for both IT pros and developers, and you can of course earn your 50 MVA points to track kind of how you're doing on MVA There's the code down at the very bottom, PythonDjango, and that will expire on July 20th of 2015, and kind of an inside joke between Susan and I, since she's Canadian and I'm American, you'll notice that I just typed out the full day rather than trying to figure it's supposed to be day-month-year or month-day-year >> And I hope every time you've used the word color or favorite that you've inserted extra Us into all those words for me

>> Yes, exactly, just sprinkle in Us everywhere Us for everybody, you get a U and you get a U All right, in any event >> All right, we know that's out, and we'll get about >> Yes, out and about

So with that, let's go ahead and roll on in to getting started with Django, and of course, the first main question that we're going to ask is what is Django, and then we'll have to get in and talk a little bit about the moving parts, and then we'll close off with Hello, Django, although when I get in and I do that demo, I'm actually not going to do kind of the stock standard Hello, Django, but rather, I'm actually going to take a look at one of the samples that the PTVS team provide But let's go ahead and talk a little bit about Django and what Django is Well, if you actually head on over to djangoprojectcom, you'll notice that they call out two things right away on their website Number one is Django makes it easier to build better web apps more quickly and with less code, and then number two, and I love this, is it's the web framework for perfectionists with deadlines

And I think that's kind of perfect, and you really do see that throughout the Django experience, throughout the framework, because when you think about having to go in and develop a website, it's always the exact same things that we need to do over and over and over again That what I'm going to need is I'm going to need something to handle authentication, that I'm going to need something to act as a go-between between my application and my database, that I'm going to need something that's going to allow me to set up a layout, so that way I've got a consistent structure throughout all of my pages And all of that, and having to do that over and over and over again, and depending on the platform that you're working with, you may have to go in and start building that a lot of scratch, which sometimes can be a good thing >> It's nice from a learning perspective, but if you're on a short timeframe, and just I think about how many times that I've been asked to build a website, it's almost always the same basic thing We have this data, we want to be able to show this data to a user, and we want the user to be able to enter new information, and we want to store the information they provide to us

A lot of times, a lot of the stuff we build with websites is basically just a front end to access the data we've got stored in a database, and it gets repetitive >> Exactly, exactly It's like you're saying the same thing over and over again, like you're being redundant >> Like you're saying the same thing over and over again and being redundant >> Exactly, yes

Exactly We're just going to keep hitting these jokes all morning long, people But in any event, so that's really one of the main goals of Django is to try and make it that much easier, and so if you compare Django to, say, Flask, and there's an MVA on Flask, one of the things you'll notice about Flask, and it's a great platform, is it really gives you the ability to build everything kind of completely from scratch It just says, hey, look, here you go, and then lets you do everything from there But on the flipside, if you're a perfectionist with deadlines, if you've got something and you need it up and running right now, Django can be a great way to get in and do that, because it provides a lot of those different things that you don't necessarily want to have to build from scratch over and over and over again

So to kind of summarize all that on one neat little slide, it's really designed to be fast for developers So many of the features that you're going to want are already built in So if you want templating and layouts for your HTML, that's baked right in If you're looking for an object relational mapper, an ORM, that's built right in If you're looking for some level of site administration that you just need to make it easy for somebody to go in and tweak some of the data inside of the database, Django provides that right out of the box, as well

And then finally, last but not least, of course, is security And Django actually does a couple of really cool things there that it provides a framework and a mechanism for handling authentication, authorization for your users, and it also forces you into best practices a lot of times, which I really like So for example, one of the things that we'll see later on today when we get into doing forms is that if you are going to submit forms using Django, it requires that you use what's known as a cross-site token, which really prevents somebody else from faking your form So if somebody looks at that and they see, oh, okay, look, that looks like a real form, and they submit data into your site that's potentially going to try and spend harmful information up, you can actually hide all of that and make sure that when a user submits data to your site that they've used your form The Django platform really kind of forces you into that, so it forces you into that best practice, which is very easy to overlook, so I really do like that

It is very easy I think to understand I might be a little bit biased, but it is pretty straightforward, which I really do like And then finally, last but not least, is it's very powerful, that a lot of what Susan and I have been talking about here this morning in getting in and building your site is we really talked about RAD, that Rapid Application Development, where I just need a proof of concept or I need something up and running right now And Django can absolutely do that But you can also use Django for high-end, scalable applications, so if you're looking for something that's going to be real world, if you're going to launch ten next great thing on the interwebs, you can absolutely build that with Django

So I don't want you to leave that little bit at the beginning there thinking, oh, well, Django is just simply kind of a toy and for proof of concepts Absolutely not It certainly makes it very easy to do that, but it also in turn makes it very easy to build those types of sites that are going to scale and give you the ability to really kind of harness the power of Python and all that >> And without having to do everything yourself, and that's I think one of the reasons Django is so popular as a web framework for Python, because we've done some MVAs on Flask, as Christopher mentioned And Flask is great

You can build beautiful websites, great control over formatting, but there's a lot of stuff you have to do manually yourself, whereas what you're going to see if you've tried Flask, the difference you're really going to notice when you look at Django, is how much is done for you, so it's just going to allow you to do things a lot faster >> Yeah, that ORM that's built right in >> I'll get to show you that a little bit later, very soon It's just they have so much time >> Yeah, okay

In any event, let's go ahead and take a look at the different moving parts that are going to make up Django, and one thing that I want to mention right up front here is that the goal of this little intro piece is really to try and hit everything from about 30,000 feet So my goal here is to introduce the structure of a Django application We'll take a look at one of the samples that's provided by the fine folks over at the PVTS team and kind of walk through all of that, so that way, we can see what the ORM looks like We can see what views look like We can see what the templates look like, and then that way, when we get into start building the model and so forth, that you're kind of familiar with all of that, that one of the things that's going to happen with Susan in the next couple of modules is she's going to show you how the ORM works, but we're not going to put an interface in front of that

And then I'm going to get in and I'm going to show you how routing works, but I'm still not going to put an interface on all that We're going to get to that, but we're not going to get to that right away, so this is sort of our opportunity to show you the different moving parts, and then we'll focus in on those moving parts in the next handful of modules >> Exactly We'll get into some more detail shortly >> Exactly

Now, one of the things that Django is going to do, which a lot of web frameworks do, is it's going to provide some implementation of what's commonly known as MVC or Model View Controller, and for those of you that are not familiar with MVC, MVC is a pattern It was originally put forth by the Gang of Four, which is Gamma and three other people that I can never remember, and I'm sure somebody in the chat window is going to type out who the Gang of Four are But if you just simply fire up Bing, and you just do a search for Gang of Four patterns, you'll notice that it will come up with a little Addison-Wesley book It's white It's got blue birds on it and things like that, but it's sort of the seminal guide about patterns, and it was introduced, MVC was, in that book

And what MVC is, is it's really three main moving parts, is it's a model, a view and a controller So my model is my data This is what I'm wanting to work with My controller is going to be responsible for taking requests from the user, loading up the appropriate data and then eventually taking that data, combining it with a view, there's our last part, and then sending it out the door So that view is going to provide that user interface

Now, one very big thing to keep in mind about MVC is that MVC is a pattern, and so a pattern is a recipe that's designed to be used to solve a problem And recipes do not need to be followed exactly If you've seen one of my prior MVAs, one of the things that you've probably heard me mention is I do rather enjoy cooking, and in particular, my dish of fame around all my friends is chicken cacciatore And so I do in fact have a recipe that I use for chicken cacciatore, but again, I play around with it I love mushrooms, adore mushrooms

I have this very basic philosophy in life If you don't like mushrooms, you need to change your mind >> You are a bit obsessed about the mushrooms >> I am obsessed with mushrooms I love mushrooms

So I always add more mushrooms than the recipe calls for I also like garlic, so I add in more garlic, because really, who doesn't want more garlic? So I take the recipe and I tweak it for my own purposes, and the exact same thing holds true with patterns, if we can kind of keep beating this analogy into the ground here So if a pattern is a recipe, you can actually go in and make substitutions, so just like with cooking, you'll make it based on allergies, the ingredients that you have on hand and so forth, so you use what bits and then you modify where it doesn't And you notice that with Django, as well So kind of a traditional MVC, and you've probably seen me walk through this slide before, but a traditional MVC environment is going to look a little bit like this, is that we're going to get a request that'll come in

It'll hit our controller Our controller is going to load up the model and do stuff, so there's our neat little model right there It's going to take that model, combine that with the view, which we see down at the very bottom, and then it's going to send that that back out to the user Well, Django does something very similar It does do MVC, but it does, and I'm just going to

there we go, bring this slide up It does it in a slightly different way, and so I've kind of broken down the main moving parts that we're going to see in Django here, and then we'll actually get in and take a look at an example in a moment to hopefully kind of bring all of this together >> Now, the question has come up a couple of times already in the Q&A, which as you talk about the views I think is just appropriate to touch on

There's been a couple of people asking if you can do Bootstrap when you're working with Django >> Absolutely, yeah You can absolutely do Bootstrap So one real quick thing about Bootstrap, if I can tangent off of that real quickly here >> Don't forget your tangent

>> But in any event, so Bootstrap is a front-end technology So that it's a set of CSS and JavaScript files that's designed to help make your front end more responsive and also make it easier to do the different things that you want to be able to do on the front end like pop up dialog boxes or have collapsible regions and things like that, so Bootstrap is going to bring that to the table Bootstrap can actually be used with any back-end technology, so if you want to use Django or Flask or PHP or Node or MVC or really kind of any back-end technology, that's just fine, because Bootstrap is going to sit on the front end And to actually go one step further with that, one of the things you're going to notice is that the default template for Django projects does in fact use Bootstrap, so Bootstrap will actually be right there part of the project And then the last little thing that I'm going to mention just because I have to mention, I'm required by law to mention this, is the fact that we do have an MVA on Bootstrap

There we go, there's an MVA for that >> There's an MVA for that >> I saw somebody had an MVA tee shirt, which I got a huge kick out of And then number two is there's also an edX course on Bootstrap, as well, so if you head on over to edxorg and just do a search for Bootstrap, you can find it there

We'll talk a little bit about Bootstrap in the last module if you want to go check that out >> Awesome, thank you >> Cool, you're very welcome All right, cool So let's go back to our Django flow here, and let's kind of take a look once again at our little user dude there

So there's our little user, and so our user is going to make a request Now, one very big thing about Django, like most other modern web technology, is that you don't actually request an HTML file say like a PHP or an ASP file directly, but rather, what you do is you basically say this is what I want to do So, for example, maybe you want to see all of the artists We're going to do a music store today Maybe you want to see all the artists, so you type in whatever the leading URL is and then /artists

>> Yes, as opposed to artistshtml >> Exactly, exactly And so the first problem that we have is what in the world does /artists mean? >> Right, because that's not a webpage If I'm not telling it artists

html I mean, if I gave artistshtml, clearly, it would go to that HTML page

So yeah, how does it know when I just go /artists what to display? >> And the answer to that is there's actually a little URL config file that you're going to have that what you'll do is you'll actually list off by using regular expressions, as we'll see, the set of different URLs that are going to be available So if you want artists to go load artists, then what you're going to do is you're going to tell Django, hey, when you see /artists, I want you to actually go run this particular code So our routing is going to figure out what the user wants So that's the goal of routing That's going to be our URL config, and again, we're going to see this in a couple of minutes

I know I'm kind of touching on it Trust us, we're going to dig deeper as we go along >> I've seen the slides We will cover this >> We will cover this

She's seen the ending there But in any event, so our URL config is going to figure out what it is that the user wants, and then it's going to call the right view All right, let's back this up a little bit Let's talk again here Remember how we mentioned MVC is a pattern and you can adjust and kind of take what you like and rework and reorganize things, as you might want? To me, and I'm just going to be honest here, is I honestly wouldn't call what both Flask and Django actually call a view a view

That's me That's Christopher Harrison saying that Everybody has their own little opinion, and in fact, if you go to the Django website, it's on their FAQ, they actually talk about this, is that some people will look at what they call a view and call that a controller To me, I call that a controller, and they basically come right back and say, hey, look, it's a pattern And so people are going to have different names and different philosophies and so forth, and this is their philosophy

So their philosophy is that that's a view, and so I guess to a certain extent, then, that URL config would be a little bit maybe more like a controller, because it's figuring out what the user wants and calling the view But the real thing that you want to take away from all of this is not semantics but rather just go with it Just it's called a view, okay, fine, it's called a view Don't get caught up on verbiage, because that's really not going to help you in the long run Okay, so our view here is going to load the data, and the way that it's going to load the data, and I just don't have this on the slide here, is it's going to load the data by using the Django ORM

So inside of the views code, it's going to have a little bit of code to go off to the database, go get the data, get the objects back and then eventually here call the template, which I'll get to in a moment You look like you want to say something >> I was going to say, yeah, so we'll talk about ORM again Remember, we're just touching on everything We're going to cover all of this in more detail later, but yeah, this ORM, basically, this is just a middle layer that will talk to a database for you

>> Exactly, yes >> As opposed to writing SQL select statements, the ORM is sort of going to take care of that part for you >> Exactly, yes, so ORM is Object Relational Mapper, if you're not familiar It's something that's going to act as a go-between between my application and the back-end database, so rather than, like Susan said, talking to the database directly, I'm going to talk to this middle layer, and the middle layer is going to go off and get my data and bring that back for me So I would have that code inside my view there, and that's going to go get me my data back

And then what we're going to wind up doing is we're going to call the appropriate template, we're going to hand that object into the template, and then the template will put together that eventual display that we're going to wind up seeing So that's what's going to wind up happening with all of this, is we're going to have our URL config, which is going to have our routing It's then going to call the appropriate view, which is going to go load the data, call the templates, and then eventually send that out the door Or I think the best way to actually do it is let's get in and actually see it, so let's do our Hello World here >> Yes, I think it's time, we said, yes

>> It is time >> It would not be an introduction to a new programming world if we did not create the Hello World project >> Although I'm not going to create the Hello World project What I'm going to do instead is I'm actually going to use one of the samples that's provided by the PTVS team, and somebody actually mentioned in the chat window, PTVS there we go about what tools they were going to need to follow along with this, and they asked about Visual Studio and Visual Studio Community, and yes, you can absolutely use Visual Studio Community

But one of the things that you will also need is the Python Tools for Visual Studio >> Yes, we've actually had a couple of questions in the Q&A for this, so maybe if you could just go there and show them where the installation instructions are, that would be fabulous, because we have had a couple of questions in the Q&A window about this >> There you go, so you notice, I just go to pytoolscodeplexcom, and right here, you can hit installation

I'm actually going to open that up in a little tab, just to make my life a little bit easier here, chugga-chugga-chugga, and you'll notice that it actually links off to GitHub, so we'll just click that And then here is the step-by-step instructions that I'll kind of let you walk through The couple of things that I'm going to mention here is you will of course want 2013 if you're using 2013, and then you are going to need a Python interpreter We're using CPython 34, but most everything that we're going to be doing should actually work with Iron Python, as well, but this is the one that we're going to be using, so you'll actually need both the PTVS tools

There we go You'll need both the PTVS tools, as we as a Python interpreter, so that's where you can go grab both of those All right, now, coming back over here to the Python Tools for Visual Studio, if I just hit downloads and give this a second to come up, you are going to notice that there is an RC, release candidate, for a new version that's going to be coming out Right now, don't go grab that They're still working on things there

If you are downloading this manually, we want 21, but here's the thing that I want point out is the PTVS samples And what I really like about the samples is they provide to you, well, a sample, that they give you a full-blown implementation, that one of the things that I sometimes find it very hard to work with is I go into Visual Studio, and I obviously love Visual Studio I go into Visual Studio, I click file, new project, and maybe I choose MVC, and I hit okay And it's going to create a very basic setup for me, that it's going to give me the home, the about, the contact page

It's going to give me the login page, but it's not going to give me anything else So if I'm just looking to learn by somebody else's example, I'm not going to be able to do that with the baked-in template And with PTVS, it's actually the exact same way, that if you just went in and you said, file, new project, and you went to Python, and you just chose a Django web project, which we'll actually be doing a little bit later It's just going to give you a couple of very basic pages, and that's it So if you're looking to learn by looking at somebody else's example, that's not going to do it for you, and that's where the samples come into play there, and that's why I really like the samples that they've provided here

They're just not in the PTVS tools directly, so you do have to go download them separately, and again, the way that I did that is I just fired up Bing, did a search for PTVS First link right there, PTVS, and then I clicked downloads and then, chugga-chugga-chugga, and there we go And then you'll notice, right down here is the samples >> Yes, and we all know coders We love to copy and paste, so it's fantastic to know where to find coding samples

>> Absolutely So let's just go ahead and call this my polls example here, and then I'm going to click okay, and then this is going to ask me, okay, well, where do you want to create this, the external packages? And typically, you want to install into a virtual environment The advantage to installing into a virtual environment, and I'm just going to let this go in the background, is the fact that this is now separate from everything else So if you decide that you want to upgrade a version of a particular add on or package for one project, but maybe not for another, this gives you that capability This gives you that flexibility

So I'm just going to let this create its own separate little environment, and then that way, everything sort of like we said, is going to be separate Now, one of the things that we're going to be doing here, I'm not going to bother uploading the samples into our GitHub repository >> Because you guys can download those on your own >> Exactly And I'm going to put up the URL for the GitHub a little bit later, but we are going to upload our sample projects into there

One of the things that's going to happen is we'll wind up having created our own environment, as well, and the way that the environment is actually managed is with this little requirements text file, so if you go download this from GitHub, what you're actually going to wind up with is something that will look a little bit like this Let me actually just delete my environment Delete Go away Yes, delete, there we go

So you'll wind up with something that will basically look like this So what you can do is just simply right-click on the project and say, I want why am I not? Oh, because I need to right-click on Python

There we go Right-click on the Python environments There we go I need to finish up my coffee this morning, and then I'm going to say, add virtual environment, and then you'll notice that it'll tell me right here that it found a requirements text file, and then when I click create, it will then go ahead and download everything from that requirements text file So when you pull this from GitHub, you're going to notice that the environment is going to wind up being empty

You can just recreate it, and then away you go from there, and it will download everything for you, which serves as kind of a perfect stall point, so that way I can have a sip of coffee >> Get your coffee there Keep it going We've got a lot of people out there who are like starting at 5:00 pm

They're going to need coffee in a couple of hours >> I need coffee now, though All right, we'll give this just a second to finish out here Moving the mouse makes it go faster, as we all know, and see, we're really live here There we go

>> There we go I was going to say, I was going to start telling bad jokes We don't want that >> No, we don't want that >> Come on, install

>> Okay, one more thing Well, one more thing One of the things that you're going to notice is, it's going to give us a little thing right here that will say before running this project, you need to synchronize the database Don't do that We'll actually talk about this more in the next module, but there's an updated way to do this rather than doing the sync database

So Susan will actually demo that in a couple minutes, but we're not going to want to sync the database when we get in and do our thing But rather, we're actually going to wind up doing it from the command prompt, so you won't actually right-click and sync the database Okay, let's go ahead and take a look at a couple of different moving parts that we've got here, and I'm just going to rearrange my windows to make this a little bit more readable, and let's go ahead and zoom on in >> Yeah, that's a lot of files you've gotten up there when you create that It's an example of how Django does a lot for you, but at first glance, it can be a little intimidating

>> Exactly, yeah, yeah There's an awful lot here So here's the main files that we want to focus in on The first is going to be managepy, and this is actually a script file that we're going to use, sort of like the name implies, to manage our Django application

And in fact, I'll actually get in and use it really quickly before I launch the site to show off how to create the database, and Susan will actually be spending a fair amount of time with that in the next module, but that's actually what we're going to use to manage our Django application, and in particular, we're going to use this to manage our database The next little file that you're going to notice is the settingspy file, which sort of as the name implies, is going to have settings, and the big thing that our settingspy file is going to have is the location of our database So we mentioned real briefly in ORM, and Susan is going to get deeper into that in the next module, but an ORM, an Object Relational Mapper, is a go-between between our application and the back-end database, so rather than me talking to the database directly, I talk to this middle ORM

What's great about that is, if I'm using the application, I don't care about the database, because I don't talk to the database I talk to the middleman And so as a result, if the database updates, the only thing that needs to know that is the middleman, is the ORM, and so we can actually just go into the settingspy file We'll see this at the end of the day, update the database, point it at a different location, and just of course make sure that the table structure has all been created, and assuming that that is all in place, we don't have to update any other item in our code to make it use that brand-new database

So we just update our settingspy file, and away we go from there, which is awesome >> And that's incredibly powerful when you think about working as a developer, too, because I worked in situations where actually at the start of a project, we actually didn't know what database product we were going to use We were actually in a situation where we were still evaluating the final decision of what our database would be, so to be able to start doing your coding and know that if that database changes from what our initial assumption was, but I'm not going to have to go back and rewrite a bunch of code, is very powerful >> Exactly, yes

So the next little file that we've got is our urlspy file, and this is our URLs config, and that's what's going to have the list of these are all the different URLs that we're going to be expecting and where to send somebody from there You know what I'm going to do? I'm actually going to just kind of type that out, so we'll just say manage We will say this is going to be our settings from there, and there we go Our URLs, this is going to be our routing

Okay, now, you'll actually notice there's a second urlspy file here, and I'll touch on that in just a couple of moments, but for right now, you can just kind of ignore that There's our viewspy file, and this is of course where our views are going to go, and our view, again, in Django terminology, means that this is going to what's going to execute our code and eventually combine all of that with our templates, which is going to be our HTML And then last but not least, there's our modelspy file, and this is where our models are going to wind up going I have lost my mouse

Okay Don't move the mouse, apparently There we go So that's where all of our models are going to wind up going Okay

Let's go ahead and open up each one of these files and kind of walk through a little bit of each one of these So first of all, there's our managepy file, and let me make sure that I'm on 16-point file, so that way Danny doesn't yell at me, and I think I am I'm good There we go

Danny, again, is our studio guy He loves it when we call him out >> That's right Hi, Danny >> But in any event, the big thing that I want you to notice right here is that this is actually going to be calling out where our settings

py file So if you decided that you wanted to call that something else, you could call it something else, but don't Stick with the convention Exactly Our URLs, as promised, is going to have a set of URLs

So the way that it's going to know what seed does or what about does or what login does is because we've registered those URLs inside of here Now, I mentioned the fact that there was that second URLs file One of the things that you can actually do is you can actually point to another file, so you can actually break it down into separate files, which can help make things that much more manageable You don't have to For simple projects, I wouldn't recommend it at all, but for things that are going to get more complex, this can really make your life that much easier

Okay, here's our little views, and I'll actually come back to this again in a moment, but what the views is going to do is this is actually going to take the request from the user, execute the code, go get our data and then go off from there, so this is going to be our code that's going to be, again, working with the back-end database and all of that good stuff Okay, then what you're going to notice is that I've got my models right up here, and our models is going to be the data that we want to work with Now, one of the things that I want to highlight here, and again, Susan's going to get into this in more detail on the next module, but the part that I've circled right there is the structure of our model So this is a polling application, so this is of course going to be containing polls, so there's our poll, and you'll notice that we've got text and we've got pub_date So text is going to be the text of the poll, pub_date is going to be the publish date, but you're also going to notice right out here, and I'm trying very hard not to steal any thunder away from Susan, but if you take a look at that, that looks very much like a database

It looks like we're kind of describing what our data is going to look like, and that's exactly what you're going to notice there >> Yes, and we're going to get into that shortly >> Yeah, exactly We're going to get into that shortly I'm not stealing any thunder from you

>> Okay, I was just going to sit back and let you do the whole course This was going to be the easiest MVA I've ever done >> The next thing that I want to highlight here just kind of real quickly is our formspy file We can actually describe what we want a form to look like through code, so that way you actually don't have to build up the HTML manually, but instead, you could actually do all of that through code

Okay So in any event, so there's our main moving parts, and all of that good stuff I'm going to real quickly here just create the database >> And I just want to point out, while you're doing this, just remind everybody, this is the Django in 30 minutes We're now going to, just to give you the overview of all the moving bits

we're going to come back, and everything Christopher has just talked about, we're going to come back and talk about in more detail and break down like all those lines of code you saw all over the screen We're going to break that down so you understand it >> Exactly

>> So don't panic I saw a couple of someone sort of going, oh my gosh, I can't keep up with all this We're not expecting you to be able to reproduce the code that he's just been flying through That's why we've got five modules of content on each of the concepts we've just touched on here, so just so you know, he said, don't panic, all these commands, all the stuff about the routing, about the ORM and the database, we're going to cover that all in good detail as we go further in >> Exactly

>> That's a nice screen you've got up there, Christopher A beautiful screen popped up on Christopher's screen, one of those ones, with a long list Did you forget to make your donations to the demo gods? >> Apparently Yeah, we came in last night I ran this real quick

This was sort of going to be our I'm going to sync the database, even though this isn't really the way we want to do that, but that's okay I'm just going to do it for right now

So yeah, we really don't want to do it this way, but I'm just going to do it this way, just because it's going to make the final product work, and right now, that's all I care about, is I just care about the final product >> Yes, like we said, we're going to go back and break everything down, so this is just to show you what it looks like, to just show you a quick example >> Yes, okay, so in any event, here is that little polls application You are going to notice that I can create sample polls right from here, and I could log in with an account if I had wanted to, but the other really cool thing is this also does provide a Django administration page, as well, where you could actually go into the back-end database and start working with everything directly there And are you going to let me log in? There we go

Yeah, it did So in any event, there is the three little polls that it creates, and if I go back into our admin page, there we go, you'll notice that right from here, that I can actually go in, start creating brand-new users I can actually start creating sites, and then you'll also notice that I can even create polls, and all of this is actually provided from Django And so you'll notice that it gives me this not very friendliest interface, but it gives me a very powerful interface that I could then use to start creating polls directly, and that's the goal of the admin page The other thing that you're going to notice here is that I could go in and click

for example, have I tried Nodejs tools in Visual Studio? Yes, I've used it, and then I could go ahead and click vote, and then there is that little poll, so it gives me all of that And then the last little thing, going back to the question that you had brought up earlier, which is about Bootstrap, this is actually all using Bootstrap, so all of this on the front end is using Bootstrap

>> Now, is this that sample application that you downloaded? >> This is the sample application >> At the very beginning, when you were showing off the Python tools for Visual Studio, there was a download option, so this is that sample code >> This is the sample app Yes, this is the sample project Beautiful

All right, so here's sort of the goal of this module So the goal of this module was to talk a little bit about Django and why you should be interested in Django It was also to introduce the moving parts So show off the URLs file, show off the models and all of that Now, here's the thing is, A, we've obviously got the rest of the day, so we're going to take a break here momentarily and kind of dig in from there, but also, B, is we're also going to start from a clean project

That as much as I do love looking at a sample and kind of learning from it, that works well if it's just me kind of sitting at a computer and poking at it If somebody is teaching me, the way that I like to learn in that case is to start from scratch So assume that I'm going to now sit down at my desk and I'm going to click file, new project, what should I do next? Well, here's what's going to happen We're going to take 10 minutes We're going to come back, and then Susan is going to click file, new project, and show you how you're going to get started by using Django, so we'll see you guys in 10

>> Great