We're sorry but this page doesn't work properly without JavaScript enabled. Please enable it to continue.
Feedback

Stumbling Through Django and How Not To

00:00

Formal Metadata

Title
Stumbling Through Django and How Not To
Title of Series
Part Number
9
Number of Parts
48
Author
Contributors
License
CC Attribution - ShareAlike 3.0 Unported:
You are free to use, adapt and copy, distribute and transmit the work or content in adapted or unchanged form for any legal and non-commercial purpose as long as the work is attributed to the author in the manner specified by the author or licensor and the work or content is shared also in adapted form only under the conditions of this
Identifiers
Publisher
Release Date
Language

Content Metadata

Subject Area
Genre
Abstract
If you’re a beginner about to embark on a new Django project adventure, this talk is for you. When I started my first Django project, I took the “Sure, I think I can figure that out” approach, which is fun! And also dangerous. But exciting! And also horrible because I caused myself a lot of trouble and barfed on my keyboard. (Metaphorically.) Oops. My hope for this talk is to pass along lessons I learned the hard way, and save the world. Or at least prevent some frustration. :) We’ll talk about version control, structuring your project, and how to handle top secret stuff. We’ll also talk about throwing house parties without causing anaphylaxis, pregnant daddy seahorses, velociraptors, and friends. I promise all of that is related to Django.
6
Thumbnail
42:19
Random numberCausalityVirtual realityAnalogy2 (number)Classical physicsIntegrated development environmentRevision controlInheritance (object-oriented programming)Installation artSource codeLocal ringUser profileAnalogyVirtual realityProjective planeMultiplication signClassical physicsGenderVirtualizationDifferent (Kate Ryan album)Group actionSoftware developerBitMusical ensembleAxiom of choiceMassRevision controlRight angleIntegrated development environmentChaos (cosmogony)NumberString (computer science)Set (mathematics)Near-ringSource codeMathematical optimizationProduct (business)CASE <Informatik>Video gameMathematicsProfil (magazine)Cartesian coordinate systemType theory1 (number)Causality2 (number)Binary fileWrapper (data mining)Line (geometry)Beat (acoustics)Normal (geometry)Squeeze theoremPhysical system
Virtual realityMonster groupData structureMessage passingBroadcast programmingGoogolInternetworkingProfil (magazine)Integrated development environmentComputer fileProjective planeFreewareCodeTournament (medieval)Monster groupQuicksortArithmetic meanBranch (computer science)AnalogyRight angleTask (computing)Query languageInternetworkingBootstrap aggregatingPulse (signal processing)GenderMobile appAdditionGraph coloringServer (computing)ArmWeb 2.0Physical systemProof theory19 (number)Point (geometry)DataflowBlogMedical imagingFunctional (mathematics)BitLogicWeb applicationMessage passingAuthenticationVelocityPasswordMultiplication signElectronic mailing listGodEndliche ModelltheorieDisk read-and-write headView (database)Content delivery networkType theoryIndependence (probability theory)Lie groupComputer animation
Virtual realityScripting languageException handlingVariable (mathematics)Integrated development environmentLimit of a functionFrequencyMobile appCASE <Informatik>Level (video gaming)Group actionObservational studyKey (cryptography)Point (geometry)Multiplication signProjective planeScripting languageBranch (computer science)Product (business)PlastikkarteBitGenderPasswordIntegrated development environmentSet (mathematics)Function (mathematics)Inheritance (object-oriented programming)Figurate numberVirtual realityRight angleDifferent (Kate Ryan album)Stress (mechanics)Address spaceFrequencyMathematicsMeasurementInternetworkingEmailRevision control2 (number)DatabaseRow (database)SpiralFunctional (mathematics)Execution unitSoftware developerSemiconductor memoryMessage passingWordDenial-of-service attackPerfect groupVariable (mathematics)GodConnected spaceOnline helpData structureEscape characterProof theoryProcess (computing)Information securityConfiguration spaceRoutingGradientUniqueness quantificationGoodness of fitForm (programming)Data miningBoss CorporationMetreComputer animation
XML
Transcript: English(auto-generated)
and calm down everything's gonna be fine I don't know why you're so worried my
name is Melanie I'm a new ish Django developer you know that saying that somebody knows just enough trouble enough to cause trouble like that's who I am so you may be asking yourself why am I listening to this
fancy-pants I don't know how you make your choices friend it's quite possible that you're lost and looking for a donut but if you're here for Django or for donuts I know what I want you to get out of this talk okay here it is not too
long ago I was diving face and brains first into my very first Django project there was a lot of chaos and confusion and carrots there weren't any carrots but I really like alliteration but it was just kind of swirls of
expletives and facepalms and general madness I made some big costly mistakes and it turns out that those are decently avoidable so that's what I aim to give you I want to lay out the beat by beat post-mortem of all of my
flailing missteps so that you may avoid crying on your keyboards and vomiting on your rubber ducks not that I did that but but you might I don't know you here we go throwing house parties without causing anaphylaxis with
Django so it's totally normal don't laugh the recommendation to me was to create virtual environments which I dismissed immediately because if I believe in anything I believe in laziness and climate change because
science and that the toilet paper goes over and not under because I'm like a decent person right yeah I also didn't totally understand what a virtual environment was or what it was going to do for me and I certainly wasn't going to unlazy myself for no good reason so let's take a look at that
really quick quick note this is a rather long analogy so just pretend that you all love long analogies especially the ones with bad drawings thank you very much there we go okay so let's say that you have built a big and beautiful house and you've made it with a massive living room the living
room is actually I can tell you love this drawing I can feel it from your heart that's awesome okay the living room is so big that you haven't bothered to make other rooms you're just like I have a sweet living room whatever so now you have some friends that want you to host a party at your
house and you're like have you seen my living room it's amazing of course I do that and so you tell them okay your friends tell you what they need for the party they need classical piano music they need hand sandwiches obviously and very critically they need there to be no peanuts because every
last one of them is terribly allergic you can do this everything's fine so here comes the second group of friends and they also want to have a party in your massive living room and you're like I can totally do that and they're like we need classical strings music okay that's fine they need turkey legs also fine and they need bottle rockets because they're weirdos
apparently whatever you still say sure everything works fine another group comes you know well oh wait we're not there yet we're saying that it's fine everything went well we're just gonna skip over how well it went it was awesome everyone wept with joy the next group comes they're like we
totally want a party you're like obviously I'm amazing at it there's already two here and everyone's having a good time and they've had this party in other places before and they bring all their own stuff and you're like sweet you just let them do their thing right however it turns out that while you weren't looking they took a whole host of peanuts and threw them everywhere and now your first group is dead so bad look at how sad
they are they have X's for eyes y'all how this relates to Django thank you for bearing through that the first group is your first project right it's hanging
out having a good time you put it in a second project also fine like it's a little bit different right but not so different that they can't get along the third project though maybe it has a different version of Python and a different version of Django and once you install the requirements file your
first project just blows up bummer and this brings us back to virtual environments the logical solution for throwing parties without becoming a mass-border murderer via peanuts is to build rooms right you build the rooms you stick each party in a different room and no one kills each other hooray
that's like optimal for throwing parties just in case virtual environments do the same thing for development you can look this up in the documentation but here's the quick basics on it in Python 2 there is a package called virtual M that we install with pip install virtual M and
then whenever we want to build a room build an environment we say virtual M and the name of the environment obviously in this case peanut-free because of the murdering in Python 3 this is built in so we don't have to install anything extra we just type Python 3 dash M V E and V full of
peanuts and it will make that virtual environment for us you need to activate the environment otherwise it's just like going back to the living room and it'll just grab whatever you have installed on your system and so to do that will type source the name of your project slash bin slash activate and
when we press enter it shows us that we've activated the environment by putting the name of the environment in parentheses at the beginning of the prompt now there's one more tool that although it involves installing a different thing which interferes with my laziness it actually enables
additional laziness later so I've started using it exactly so it's called virtual M wrapper and we install it with pip install virtual and wrapper just like we did before then oh my gosh we have to take a second step by adding something to our bash profile you can look this up also in the
documentation for virtual and wrapper later but this is what it looks like oh my gosh it's so much it's two lines but all of this allows us to do this later we just type MK virtual M and the name of the environment to make a
virtual environment and it automatically when you make it activates it for you as well so you don't have to do the whole like source whatever that stuff was that I said later when we want to work on it we just type work on and the name of the environment and it activates it for us did you forget the
name of your environment of course you did you're a human person just type work on press enter and it tells you all of your environments oh my gosh they're all there don't you love it yes okay next saying no to see monsters
and yes to pregnant daddy seahorses with Django when I started my first project what I understood understood myself to be doing was building a web app right it's an app there's one you're building here we go got it so when you're looking at the commands that we use to create a Django web app
we use start project and then we use start app which is obviously still kind of your web I think pretty much so in my mind we started a project we started one app because we're only making one app right something like this
and then we would just shove everything into that app and it would be awesome why would you make more than one app well there are lots of things that we typically need to do with a project in five up my tiny baby project I have to store a collection of images that I curate I have to store
messages that users enter and I have to schedule and send messages providing this functionality requires a bunch of models and views and other fun stuff if I try to start one and only one app this starts to look a little monstrous you have one file for your models you have one file for your views
and everything just gets like bigger and bigger and look so now when you go back to find code for a specific thing that you want to adjust it's just kind of like a miserable task that looks like that and makes you dream of scary things so we use apps to avoid this but we don't want to just be like
this is messy and long so I'm gonna make a new app and then just it's like whatever what you want to do is think about each thing that your project needs to do and make a separate app for that so with five up I started out with everything all jumbled into one app called five up creatively but I
eventually transitioned to have an app for curated messages an app for custom user messages and an app for sending messages as well as this authentication thing that I made that's a little like right and I accidentally named it F you off for five up right dang it so what we've done is instead of
taking our baby seahorses and gluing them on the dad's like head neck and back and feet seahorses don't have feet they have tails gluing it on their
tails we've left them as their own little adorable things and put them in the protection of the daddy seahorse oh so cute they're so happy in there okay side note on this I decided on this analogy before I had googled what a daddy seahorse looks like and oh my god it is terrifying like it's the stuff
of nightmares don't do that protecting your velociraptors with Django so in my voyage through my first Django project I came across this blog post
sorry friend that wrote the blog post I don't know what your name is so you don't get credit haha just kidding whatever anyway the blog post told me to save all of my static files locally so this means that when I was using bootstrap in addition to linking to the CDN I would download all of the CSS files and all the JavaScript and save them in my static folder
recalling that I am excessively lazy this did not sound like something I wanted to do surely that was at least two more steps no thank you and why why would you do this allow me to illustrate my disaster let's say that I found this really amazing G query thing that does something awesome
something possibly like this haha that's amazing and we also know that there's like a ton of really useful reasons to put a velociraptor on your website don't even pretend like there is it anyway my thing was like a modal which is way boring and doesn't have any dinosaurs in it but anyway so we'll
just pretend that I did the dinosaur thing because it's better anyway so I do this amazing thing right I go to a coffee shop to continue working on my amazing things and I don't know the Wi-Fi password and like the barista looks really busy and I didn't want to bother them so I thought to myself hey
I'm working in a local environment I totally don't need the internet internet doesn't own me internet totally owns you anyway I started up my local server and I go to the whole like 127 blah blah blah whatever it is only to discover that my velociraptor is gone and everything looks like 1992 which was not an amazing year surely I have done something horrible
right because I'm a beginner and I've done numerous horrible things at this point so I just start ripping apart my code that's logical right I just am like digging through everything and changing random things and like I don't know I screwed something up let's ruin everything there was a lot of ripping
apart so eventually I decide that I need to google this right because that's what you do so I go and like beg the barista for the Wi-Fi password and I got like I look up like one thing and then go and refresh my server and my beautiful velociraptor greets me again tears of joy and that's when it
clicks that the only thing that was happening was that because of my lack of internet I couldn't access like my CSS files JavaScript files anything that mattered files and that's what happened all of my independence from the internet was a lie if I had saved those files locally I wouldn't have had that problem
right so there you go which brings me neatly to my next topic terrified abandonment of drugged full mistakes in Django all of this was happening on the one and only copy of my code my master branch
senator remember that lady she was like I'm gonna restore that 19th century fresco Jesus it's not that my project is like an amazing piece of art
but like maybe we both should have made a copy first and we recall how much ripping apart I did it was quite a bit and while my renewed internet access solved my velociraptor problems that's the last time I promise
so cute anyway it didn't solve all the new problems that I had created because I had gone so far down the rabbit hole of fixing non-existent problems I had no idea how to get back to where I started this is not great I honestly don't know how I got back to where I was I just kind of like
and then eventually it worked out because that's basically what coding looks like right I mean I don't know like I said I'm not experienced I assumed everyone does this anyway you don't have to tell me about that since that time I've discovered what I can essentially use as gets version of
panic button it's get branching it's amazing so instead of using my anxious confusion to destroy all of my work I could have done this get check out B to create a new branch appropriately called oh my god what have I done and
then I could commit these changes to this new trash branch with an appropriate git commit message made a giant mess of things and then I could check out the master branch and pretend that none of it ever happened which is what I do with all of my mistakes hooray so at this point I've
gotten in the habit most of the time of just creating the branch first before I get myself into trouble so now my workflow looks like this say I want to remove the velociraptor because I promised you all I wouldn't do it anymore sad face I don't know why you don't like velociraptors anyway so I
would make my changes and once I've confirmed that the changes are good then I would commit it and then check out the master branch and merge the changes you may need a different workflow based on the team that you're working with or other things I don't know but the point is if you're going to
make changes make a new branch first unless you love drama then do what you want like I'm not the boss of you okay last two being suave and mysterious with Django surely I couldn't have destroyed more than this right I mean
this is quite a bit at this point it's getting ridiculous so wrong friends it's very wrong and this one actually feels like really tricky like I've been tricked or something like I know that's not the case but like it's super feels like that and it was actually exacerbated a little bit by the fact that I'm using it responsibly somewhat so what could it be let's find out it's a
mystery okay so this is my settings file right this is the settings file that happens when you start a project in Django and notice this lovely warning security warning keep the secret key used in production secret it doesn't explicitly tell us how to do that though so when the time came to deploy I
thought well that's a cute idea that I don't know how to do let's just push it up and so that's what I did yeah I know as it turns out this project also needed my email address and my email password and for good
yeah I know for good measure I went ahead and put in some API keys and like a portion of my seventh grade diary why not yeah so please do not shame me publicly right I mean I think that's actually what I'm doing right now
because this is gonna go on the internet but anyway I guess just enjoy my shame and hopefully it will save you some trouble in the future you don't ever do this right so I'm going to if this is something that you're going to do I will tell you how not to it's just one way to do it there's lots of different ways so but this is what I do remember when we were
talking about virtual environments aside from keeping people from dying of peanut allergies metaphorically they can also hold our deepest darkest secrets that way our secrets aren't going to get into production and they're not going to get into your get history like mine so we're going to go to our
activate script for me since I'm using virtual in and wrapper all of my virtual environments are in an EMS folder and so we'll go to M's extra peanuts then activate and we'll open up that activate script and add this bit to
the end this is going to set a variable and export it with your actual secret key okay now in our settings file we'll add this function I believe this is what's recommended in two scoops of Django so if you don't have a photographic memory you can look it up there then in our settings file
instead of having the actual secret key we'll put this function and what it will do is that it finds our environment variable that we set an activate script and you're all set so it's all super fancy and mysterious
when you deploy you'll set whatever environment variable you set in your activate script there as well in Heroku they're called config variables but they could have different names depending on where you deploy find that place set your variable and you're all set that way if you're working locally or if you're deployed it will find the variables that it needs and they'll be
none of this would have been even remotely possible without the San Diego Python user group San Diego PyLadies and of course our blessed mother the
internet but the most important by far of the three is San Diego Python user group and PyLadies this is where I've gone nearly every Saturday for the last three years for encouragement for help for camaraderie our Saturday study
groups are what made me believe I could do any of this to begin with and I've found a place where it's okay to be at whatever level of your learning that you're at our study group is absolutely why I'm here I can't stress how wonderful and important our community is and I want to show you something
really quick that I worked on for literally hours like six hours I couldn't figure out why I could submit a form but it wouldn't actually save a record to my database and I worked on it like crazy and then 60 seconds at our study group brought me this it's one character for every hour
I spent that makes me feel good about myself special thanks to Micah for helping me on that one even though you laughed at me a lot during the process and the amazing thing is that a couple years later I was able to do a similar teeny-weeny fix for a perplexing problem for a new developer this is
why we need community I'm still learning I hope I never give up the title of learner because I find that it allows me to be kind and generous with myself and I think the most costly mistake we can make is to stop
expecting mistakes and start demanding for perfection from our silly flawed selves in the words of Brene Brown there is no innovation and creativity without failure period so in conclusion I wish you tidy development
environments adorable Django project structures internet connection proof velociraptors easy get escape routes mysterious secret keys and passwords super smart friends and lots and lots of mistakes just hopefully not
these exact ones that's the end thank you