📺 Develpreneur YouTube Episode

Video + transcript

Django-Python Application Tutorial Part 1

2021-06-01 •Youtube

Detailed Notes

It is time for us to take our Python and Django skills to building a full application.  This is part one in a two-part series of tutorials where we build an application from scratch.  This series will walk through all the steps required to build your own solution.

A Python/Django Site Monitor

The application we build is a web solution for monitoring web sites and API end points.  We can configure the application to simply do a heartbeat check or validate the content returned.  This first part of the series focuses on the database, design, and front end pieces of the application.  The "guts" of doing the checks and scheduling them is covered in part two.  The bulk of our tutorial covers the Django steps, but there is plenty of Python to learn as well.

Transcript Text
[Music]
so
starting into this one um
i do this this is a python django
example i want to build an application
when all is said and done
that is a essentially a standalone that
you could sit down
walk through this code have a pretty
good framework for an application and
then
extend it as you need i'm going to try
to make something that is
moderately useful for everybody
and uh something that you can get there
are better tools for it but if you want
a quick and dirty solution
then this would be it um
what we're going to talk about today i'm
going to get as far as i can
i don't think we're going to get really
into
implementing all these pieces but we'll
talk about them so
this is from scratch we're going to
create our application uh
and talk about getting that in the
database i'm not going to code as i go
too much i'm really because it is a
somewhat fair amount of code it's
probably a couple hours worth of code
that was
that we're going to look over but i'm
going to walk through it
and talk about some of the key uh things
that you know decisions and
how we get there and then of course
although i don't have it right now
uh afterwards i will put it out in
having a public github somewhere so that
uh you guys can take a look at you pull
it down and play with the source code
to your desire so we'll create the
application
focus on the database model in the
background set up our screens
tie the screens to the model and then
we'll talk a little bit about the
backend process but we're really gonna
those last
couple items we're really gonna flesh
those out more in another session we're
just gonna
try to set the table where we can for
some of this this time around
so start with the application the
database
um we're going to call this monitor
and uh it's name of the application uh
you can call it whatever you want
but uh what we're going to do i'm not
going to show this
i'll show you sort of the results of it
although we could
i'll probably run this one real quick
anyways with a different name
but the way we start as and we've done
this talk about this before the way we
start a django application
once it's installed and we have examples
of that elsewhere so i'm not going to go
back through that again
but once you have django and python in
and ready to go then you just run django
dash admin
start project you give it a project name
and as you'll see it's going to it
builds out some
some structure a folder and things like
that so you're
off and running you're essentially ready
to run an application right then you
could
from there start and it'll spin up a
little app for you
we're gonna focus in on since we're
going to the
the database first we're going to tweak
the settings because we're going to go
from the
default uh sql lite that they have built
in with it we're going to flip it over
to a
mysql database we're going to point to
that
we'll talk about creating the database
and a database user
set those guys up in the settings and
then do a you know basic connection to
it
now stepping back the application itself
is going to be well actually i think i'm
going to talk about the application as i
look at the model that may be
a little bit easier way to look at it
so let's flip over
and let me do this let me take
one of these
and actually go with this one and i'm
going to blow this up a little bit
for this first little bit
and pull this up a couple more times
there we go
so the first thing i talked about is we
can do if you want to create one is you
do a django
admin uh start application
and give it a name so i'm just going to
call it monitor 2 for now
oops sorry it's not start application
start app
notice django actually this is a nice
little thing django's pretty friendly
um and i've seen a couple other things
like that i think ruby does this as well
where it'll help you out a lot of times
here did you mean and so it's like oh
actually yes i did mean that
so it sort of guesses its way into stuff
so now
uh i ran through that and if i go to
monitor 2 then it just created this
monitor 2 database
and then it created an admin apps
migrations models test views
and if i look at migrations
then there's there's really nothing in
there but it at least starts with that
very simple structure and so i actually
can go in here
as i mentioned uh let's see
whoops i miss one here
did it
did i miss a phone somewhere
oh wait well interesting it did not
build normally it builds a manage.py
and i'm not sure why i didn't get it
this time let me check real quick
start project oh i'm sorry it's not
startup it's a project my bad
so i didn't mean startup i meant to
start project
let's do rf
monitor 2 this is why i tried not to do
too much
coding
we talked a little bit about apps before
within a you have projects then within
those you can actually have application
multiple applications and so
at this point i've got a project and it
builds by default
the an app with the same name as the
project but i could actually add
additional things which we may look at
at some point where we would do maybe a
a front end a backend an api things like
that
but now i'm gonna keep it simple so once
i've built it
it's it's built a you know fairly simple
couple things it's got some settings
some urls
not a whole lot that it's built but i
can go in and i can do
a run server
and it's running it's going to tell me
there's we've seen this for it's going
to tell me if there's some database
migrations because i have not set up the
database
but then if i go out here somewhere
then i can see and i'll pull this up a
bit i can see where
okay it's you know i'm running my django
server
it's got links oops let's put this here
like this a bit and it's got links so i
can learn some stuff about
django if i wanted to or you know for
here this is just basically say hey i've
got this built so now
i'm going to flip over to some code here
so one of the first things we want to do
is we have to create our database
and if i can find where i put here we go
so one of the things is first thing i do
is i'm going to call this
database monitor and
this is a little bit getting into the my
sequel side of stuff but
um just so you know it's creating a
database is very simple you come in log
into my sql
say create database name the database
boom done you have a database
it's like any tables really of use but
yeah you've got a database you can work
with
uh in this case i actually go in and i
create a user and this is
got a nice little case issue there um
i created a user for this database and
i'm just going to call it uh
mon owner for the monitor owner and i
give them a password
and i need to do it i'm going to do it
for whether i'm on local host
or you know if it gives me if recognizes
me by some sort of ip address
and then i'm going to grant all the
privileges and so what this does here
is um creates this user mod owner
and then i get all the privileges that i
need to be able to administer
the monitored database so if i wanted to
jump
over to
my monitor database oh actually i can
say so here
so once i create it i'm going to log in
as mod owner
and then i have the monitor database and
i'm able to start working with it
so the first thing i've got to do
because i'm going to
not use the sql light that django
provides
is i have to make sure that there's a
database i'm going to connect to django
will not create the database
that has to be there and i need to make
sure i've got a user because
once i have my user and password that
allows me to connect to that database
in order to do so i have to jump into
the settings
in which um let me do this real quick if
i look at monitor two
monitor two um there's gonna there is a
settings that is already that is
generated
from start uh some of these files we're
gonna talk about actually we're going to
we create them uh they're not created
from scratch but just
so you notice this is one that is and
most of this information
is in here there's a lot of as i talked
about the django
friendliness there's a lot of comments
around what are we doing how do we set
this stuff
up what do we need to do
and with our settings right now
the first step we're going to do is
we're going to come down and we're going
to find a section on database
and by default
let's look at this real quick
default this may be a little hard to
read
uh but by default the engine is going to
be sqlite
and it's going to connect to a little
sqlite database which you can see
i think it actually creates it somewhere
in there
or maybe that's when yeah so it's
already created a little
uh database there the sql wipe
so that you can actually work with that
you can if you didn't want to use my sql
you could go right in and you could
start using sqlite
right away we're switching gears a
little bit and so what we're going to do
is we're going to come in and set it up
and say that we want to use the mysql
backend
we give it the username of what or the
name of the database the name of the
user we're going to connect with
and the password there is as part of
setup you may have to install using pip
which we've talked about in the past you
may have to install the mysql client
we covered that in previous uh
discussions so i'm not going to
you know rehash that and then once we've
done that
then uh as that being once we've set up
the database and connected to it
so we can connect to it then all we need
to do and i'm going to do this
in the monitor two sense just to sort of
see it
is then we can come in and all we do is
we do a python run it against manage
and we can do make migrations
i'm not sure if it actually and then we
give it the application name
or project name
uh whoops oh and
it's going to say no installed app
because the one other thing we have to
do at this point is we have to add our
application to installed apps
for some reason when it creates one it
doesn't do this but this is going to be
your name
your application name so here i would
have to
go into the settings for monitor 2
and change it over so i'm not going to
mess with that too much because i want
to get too deep into the code
but what we'll do is you do make
migrations and so let's flip over to
monitor
if i can pull that code up a little nope
i can't blow it oh
there we go let's blow that up a little
bit more
so in here i can do python
3 if i spell it right
python 3
manage if i do make migrations it will
go through
and make some but there are no changes
detected because i've actually run this
and then you can do migrate so in your
case the first time through
there's not going to be much there
aren't going to be any migrations the
first time we're going to make our model
and then we would run make migrations
and then we run migrate
and it's going to up it's going to
update stuff
in this case i can see where there's
this admin auth content types and
sessions those actually all are supplied
by django and then monitors my
application itself
and i don't have any migrations at this
point
so if we were to run all of these then
we would be able to run our application
and we wouldn't get that warning that we
got
way back here that said um
go back here oh i'm sorry it's over here
we wouldn't get the little warning here
that says you have unapplied migrations
so if i run it on monitor two
where i just saw that i don't have
uh migrations that haven't applied then
i just get a straight
you know it checks a couple things gets
itself set up and then boom
it's running so let's go over to because
we're focused on the database let's flip
over to the models
and let's shrink that down a little bit
now models is one um
let me go back to here
that is not included so you know when
it's first
built we're going to have to we'll
create this models.py
and it's one of these names that it's
going to be looking for
i think we may see it here i think
there's a note on that somewhere
oh no it's not in here so we're going to
go in and models is
basically where we're going to source
our information for our database
as we saw when it attempted it there was
a couple different
applications auth and things like that
that were supported by
provided by django well this is what
we're going to provide with our
application
so models.py within an application
is the model for that application
so one of the things we have to do is
we've got some imports we've got to do
from the start
and basically this is django db and the
contribute
models actually really you just need
import models but what we're going to
find is that
when we start using if we use security
or if we use
well really it's security stuff or if we
have dates we have to import some
additional
pieces so i have those up there but
really this first one is what matters
because we're going to see every one of
our models
if you remember this is how we do
inheritance so this lkp
ping or lookup ping inherits from
models.model
and that tells the system in the back
end that we're going to be creating a
database
based on that now what we're going to do
in this case is we have one and this is
where i'm going to start talking about
the
application itself that we're building
this time we're going to drive this off
of one primary table
and it's sites and what site
what a site is what an entry and a site
is it is a web address
uh could be a site could be as far as
like a website it could be
an api address it's just pretty much
anything that we could
you know any url so it may be a straight
uh address it may have a a port number
it's whatever it needs to be and the
reason we're going to provide that
is because we are going to have that as
an address
where we can do some sort of a
essentially a heartbeat a heartbeat or a
ping or something like that
of that site to see if it's up and
working
now the reason that we've got you know
so we're
talking about these columns now in these
fields so each site we're just going to
have
which we just sort of talked about we'll
have a name a description and a a link
i don't have that image like that
shouldn't be there i thought i got rid
of that i'm sorry we're going to call it
a url
so we have a name and description and a
url and this is
so we can identify what the site is and
also
this address so that we can reach it now
note that we have uh character fields so
name and description are just
they're just text you know one's uh 50
one's 250 so the name we're going to
keep it sort of small
and the description we're going to let
it get a little bit longer
and then the url we're actually making
this a url
field and so that tells django that it's
something
it's got some additional validations and
things like that i'll try to get that so
it doesn't
pop up it's going to do some additional
validation
and have some basic widgets and things
like that that we can use for it
last check is just a date and within
that we are going to
that's the last time that we did a check
so we're going to you know do periodic
heartbeats essentially
and ping is going to be um
this is going to be a lookup we've got
three lookup tables
in each of the lookups i guess i'll jump
to that real quick we're keeping very
simple they just have a code
a name and a description really the name
is user friendly
the code is essentially going to be the
primary key
although each of these has an id field
in the background
uh we're going to use this code as our
primary key for looking up values
and instances records within each of
these lookups
and we have the ping which is
essentially what type
of uh heartbeat are we going to do is it
just a get
is it a ping is it a git where we're
going to actually check the value
the responding value uh it could be a
put you know something like that so
we've got to we're going to have a
couple things that we're going to be
able to support
we'll start with very simple and you
know we'll be able to extend as we need
to
result is what kind of result we're
looking for
and this gives us essentially a type
that will be easy for us to check
against
so that we can say whether it's a
failure or not so the result could be a
failure or it could be that uh maybe we
got a 200 code or a
400 code or a some sort of a value
return back and then we can also check
that value to make sure it's the right
value
that was returned and then frequency
has to do with how often we're going to
be able to do that we're going to want
to do these heartbeats
we could do it a certain number of
minutes a certain number of hours
certain number of days
and so if we look at so that's
our ping is our type is how are we
testing to see that what are we doing to
verify that this site is alive
essentially
we have a desired result which is
basically saying what you know what
results should we be getting back
it may be result value as well so maybe
we get a 200 as a desired
result but you know or essentially what
we're going to call
uh whatever we name that but there also
may be a result value so for example
a an api call where maybe you send it a
specific
call and it needs to send back a
specific value or string or something
like that
and then uh so frequency type and
frequency is
you know are we going to do this we
checking every minute or checking every
certain number of minutes certain number
of hours certain number of days
and then the frequency is that number so
if my frequency type is minutes and my
frequency is five
we're going to check every five minutes
and i've just got some basic audit stuff
of when the record was created and when
it was last updated
most of these we've covered in the past
we have foreign key relationships for
those lookups
most of this is text we do have a couple
of dates
and some integers but nothing terribly
interesting here
we do have our url field and then all of
our lookups are
essentially identical um maybe note that
we have the
uh two string we do this because these
are going to since these are going to be
lookups
when it does a lookup the
value that we see in a selector is based
off of this
the string function so we're going to
make sure we go off of the name
as opposed to the code or the
description uh description could be very
a bit lengthy for a drop down uh
and so and then in the the site itself
if we want to list the sites we're just
going to go by the name we're just going
to keep that very simple
so that's our model and then we can go
in
uh we once we've built this out then we
would go in and do our make migrations
and then
migrate and at that point
we will get a database um
i don't know if this is yeah i can't
blow this up too much
but hopefully you can see here
uh within this if i can go let's just
flop
i'm sorry i can't get this any bigger um
but essentially what i've got here is
i've got a list of tables that it
generated
i can see uh
remember i talked about that auth
application well the
table names if you in case you have
forgotten the table names are prefixed
by the application name
so these are the auth related tables the
ones under uh auth underscore
i've got the django related ones which
is uh the admin and the session stuff
and then monitor is my monitor is my app
and i can see where i have my sites
table
my lookup result lookup ping and lookup
frequency
and actually since i did just delete
uh i did delete a column out of this
in my model let me make sure i
saved it we can actually that gives us
an example to play with a little bit
so now i can go in if i do make
migrations
then it's going to go in it recognizes
here that i remove that field img link
from sites
and then if i migrate
it's going to execute that
and so it applied this monitor remove
sites image link
and if we look over on we've got a
migrations
folder and we can see each of the
migrations so i can see here this is my
initial
so i came in and it created the model
for lookup
uh frequency ping and result created my
initial sites table
and then i came in and i tweaked
i think maybe i added a result value
i came in here and set a couple of uh
properties around a few of these fields
and then i come in here
and it's going to come in and remove
field image link which i just did
so i can actually see my entire history
of changes to my database
as well
let's see i think let me go back and
make sure
and then um just for grins we'll go
ahead and whoop sorry
here i'm gonna run this
i can find my run server line real quick
there we go i'll close that out
oh i'm already running it i'm sorry i'm
running it over here
and let's just make sure we close it and
reload it
and from that now i'm going to see now
i've got a couple other things here but
now my site is up and i want to actually
flip over to the admin side
remember because uh this sort of
somewhat for free we've got and i'll
show that in a minute
um is that because we built this
we can actually see the um on the admin
side we can see our
tables groups and users is in there by
default
frequencies i can see what the
frequencies are that i've entered i can
look at
ping types i can look at result types
i can see some sites that i've already
done i can add those so i can do all of
this through the admin but we're going
to have a front end
and as a reminder uh
the authentication authorization that's
an application that it's it's already
built those
into this admin side monitor i had to
add them
and i had to do that through admin dot
py
and that is one that i'm pretty sure i
have to create
let me double check that just to be sure
uh yes i do have to create by default it
does not have an admin dot py
but if i want tables to show up here
then i need to do this which is um
pretty simple i have to import the admin
from djangocontrib and that
says that i'm hooking you know i'm
connecting to the uh the admin
app essentially and that's what that
admin is
and so for each of these uh and i'm
going to pull my models
since i did it for all of these guys so
i'm going to do
um lookup frequency ping result insights
all four of them
and then with each one of those all i'm
going to do is create a
class that inherits from the model admin
for each of those
i get a display a list of columns i'm
going to display
which is here on the list so i can see
name and url
for these it's going to be name and code
and you can see that name
code name code name code name url
if i wanted to add another column um
let's see if i think i can look up a
result i think there's a field there
and i can add that actually let me go
look at my model real quick
uh oops
uh let's see well let's just
now let's do less yeah let's do last
check
so if i do last check over on admin
then i'm going to see it's going to do
an update
which it did
and now if i look over here
sites gives me the last check field as
well
so i can play around with that as needed
but i can fairly as we've seen before i
can pull these things into the admin
and then all i have to do so i create
the class
that is essentially the admin model
form based on this i mean all that
behind the scenes
django knows what it needs to do and
then i just register i just register
each of them
and
basically just say you know what i want
to call it
and or what the model is and then what
the
admin class essentially the form class
is
so i can pull those guys in and i'm
ready to go so that gives me my database
now i'm going to talk a bit about
um we did let's see we've sort of gone
into the model
um i sort of skipped ahead to this a
little bit but that's okay
uh so just summarizing that a little bit
primary table is sites table uh we've
that's where
we're going to list our information
we've got some lookup tables that are
basically just
support tables for that main table to
give us an easier way to enter data
we do need to create a super user and
we're going to talk about populating
tables
and fixtures next so creating a super
user
is uh moderately simple
you just say let's see i think i have it
specifically otherwise i may have to
look it up
because i always forget even though it
is rather simple
where did i put that
i don't have it okay i think it is
i think it is just let's do this i think
it's just called yeah create super user
so what i want to what i have i've
already built
but let's say i want to go into uh
monitor and actually let's do it this
way
let me go there we go
go back over to monitor now right now
if i look in my oh i got to keep that
running
let me look at my users real quick right
now i have a user named rob
that i created so that's my only user
and this user is has a staff status
so it's you know basically it's a super
user
i can it's active and it's staff
if i want to create another user so let
me create
i'm going to create a guest then that's
createsuperuser
so i've got that all i have to do is
just say
createsuperuser just ask me what the
name is and so i'm going to call it
guest i give it a email address
give it a password i think it doesn't
like
super simple ones but let's find out
yeah so if it's too kind i try to use
password123
and i can it'll save you know you can
bypass the validation you want to which
i'm going to because
i don't need to worry about it so now i
will be able to look in here
if i refresh whoops i got to start my
server back up
and then refresh and now i can see that
i've got guest user
um and again i can see that they're
active their staff their super user
but i'm going to go in and somewhere in
here
delete
and we talked about these uh users and
permissions and things like that in the
past i'm not going to rehash that too
much
particularly because it's not going to
matter too much for our application
one of the things that we need to do is
we're going to need to
do uh enter in these lookup values to
some waveform or fashion
now we've got this uh this interface
that allows us to
you know fairly easily do so it's user
friendly good user experience
but i do want to mention i want to
mention something we've done in the past
or that we haven't really covered the
past which are fixtures
and those allow us to along with the
data migrations
we can use those to develop on one
machine
and those remember those migrations are
sql scripts
so i can go run those same migrations
i can run those on another server and
update it fairly quickly
what migrations don't do is handle data
that is where fixtures come in now what
a fixture is is i can take a look at
a table uh for example
let's do i think results because i don't
think i've done that one yet
let me go look real quick in my folders
where did that go
here it is so i did frequencies before
so
for results instead of me having to
update my database and go do this again
i can actually do
a dump and that's where fixtures come
whoops
let me do it this way that's where
fixtures come in
and so what a all i need to do with that
and i'll show you what a fixture looks
like
i'm going to go in and i'm going to do
with manage again we're using this
python three manage
we do a dump data we give it the
application name and then we give it
the table name so this time i wanted to
do lookup result
yeah look up result uh you can give it
an indentation because
it's basically for pretty printing and
things like that and then
i'm going to put it into the fixtures
folder
and i'm going to call it results.json
because it's going to generate a json
file so i'm going to do that for result
and i'm also going to do it i did it
already for frequencies but i'm going to
do it for
pings
and then we'll take a look at those
because then what i can do
okay so i can i've generated these
and now that's the i use dump data
load data is the reverse of it and all i
do with that
is i just tell it what fixture i want to
use i tell it
the app and the table and it's very much
a similar kind of command
and it'll actually pull that it'll
insert that information into the
database
so i can i'll do that in a second here
so let's
look at these first so let's look at
results
if i look at my data i had
uh failure value response is alive and
simple response i had these four items
when i created the um the fixture
then it creates just a nice little json
structure for each of those records it
tells me what the model is
so here's my app and my table what's the
primary key
what are the fields and the values and
then it just does that for each of those
so i can also do that for
ping i can see where i've got it for my
ping values
and i can see it for my uh frequencies
as well
now note that it has the model within so
technically i could just
combine all of these uh the data from
all these tables into one
shot and try to pull it in um
but it's easier to keep track of doing
it separately so
there's some way there are some advanced
things you can do if you really if you
have to pull like an entire database and
want to do that
through django as opposed to the
databases uh
you know bulk load and backup and
features like that
but for now we'll keep it you know
simple you can do it on a table by table
basis
and what i can do is and i'll show an
example of
load data so i'm going to do the
frequencies so if i go into
my database and look at frequencies
here's my data and i'm just going to get
rid of all of the records in there
so i've emptied my table
uh it i think it's okay with that
i didn't like that for some reason let's
see
oh i'm sorry because this has got
foreign keywords oh because i've already
got a record in there so let me get rid
of my site
come here if i can double click properly
there we go
my mistake i forgot that i had
we had a record there so if i come into
frequency now
i can take all of those get rid of oh
now let's just do it this way i'm gonna
come back there we go okay
so now i've emptied those out
but now if i wanted to come in and load
it
should look up frequency right right
um oh probably have the wrong
i think i called it look up oh what did
i call the fixture let's go look at that
real quick
i called the fixture
frequencies.json so
and so now it installed four objects
from one fixture and if i go back and
look at my data
i can see where it installed each of
those i went ahead and pulled those guys
in
so i could do that on another database
if i wanted to take this application
and quickly migrate my entire database
including data
then i can use those fixtures they are
also useful from testing and things like
that there's some there's a lot of
different uses for it
the built-in test system actually makes
use of fixtures behind the scenes
so this just gives us a good way to move
data
back and forth
so that gives us a way to create our
model create our data
and back it up you know move it around
so that really is that second working
session so now let's
switch gears into the front end we're
going to talk about
our screens for our application our
pages
and they're really we're going to keep
this sort of simple we're going to have
a home page
there's going to be some base
navigational stuff
uh like a base menu
we've got a header and a footer for our
pages we're going to talk about we're
going to have a style sheet that we use
for application we're going to pull some
stuff in there
and then we're going to have a screen
that allows us to add or edit a site
uh one other one going to do is we'll be
we'll have a
which is essentially going to be sort of
the home page as well is we're going to
have a list of
our existing sites
so to do this we're going to create some
more files and
fill these things out and this is where
there's going to be a lot of code i'm
going to go through but i'm going to try
to
walk through it somewhat quickly because
it's
it is moderately repetitive so hopefully
you guys will be able to
easily take a look at that when you pull
down the code
if you want to build your own example
then it should be easy to read and
modify
so we've got a couple of things that are
key i guess to building a page we have
to have a url we have to give it an
address
we have a view which basically says hey
when i get to this address
this is what i'm going to do we're going
to build an html template because we're
it's sort of as a you know jumping the
gun a little bit here but when we build
out a view at some point we're going to
display something which is going to be
an html page
maybe with a form within it
and as part of those html pages we're
going to have a template which is going
to be sort of our
basically we're going to be storing our
header and footer things like that in
there
and then we're also going to talk about
our style sheets so that we can
give it a general look and feel
let's see so we jump over here so let's
start with our urls
let's see we can close a couple of these
down a little bit simplify a little bit
let me close a couple of these off
so start with our urls now urls is
actually generated
um you have some by default
so i'm just gonna do a cat monitor two
monitor two oops monitor two
uh by default there's very little that
it gives
which is and that little is the admin
site if you remember when i did
fired up monitor 2 i was immediately
able to flip over to the admin site
and that's because it's built that slash
admin
if i do anything else on it then it's
it's going to tell me that it can't find
it basically
and i think we have seen that before you
will see
an example somewhat like do i have that
running in the background
i do not let me run my server again and
i'll show you an example if so if i come
in
and give it an address that it doesn't
know what to do with it
it's going to say hey so um i'll just
call it mistakes if i try to go to that
page mistake
it's going to say page.found and it's
going to show me this is what
is actually defined within the url so
these are the patterns that i register
that i
recognize now notice
i'm seeing this because i have debug
equal to true in my settings file if i
change that to false i'm not going to
see that i'm going to get a standard for
a fuller page
so while we're working on this while
we're developing
you know debug on we're going to se or
equal to true you're going to get a lot
of useful information
this one for example i don't know how
many times even building this little
application
where i had a typo or something like
that and i could easily
say oh here's what i'm looking here's
what i sent here's what i
you know oh wait this is what i meant to
send and so i can correct that
and then it'll direct me accordingly
now it includes the uh admin
and uh by default and that's the only uh
and uh import path which is this uh
the patterns we're looking to match i'm
keeping them very simple you can
actually get more complicated with your
patterns uh you can do
uh regular expressions and things like
that but i'm going to keep them simple
one of the things i'm going to do is
from monitor my application i'm going to
import views so it's going to go find
views.py
which we're going to go fill out here in
a little bit
and from the django piece
i'm going to import include because that
allows me
for the uh the user authentication piece
that i'm going to use
i'm going to go ahead and include in uh
accounts
and then i'm going to take and i'm going
to have so slash account which i could
be this could be users could be a lot of
different stuff but i'm going to hang
off of the accounts url address all of
the urls
that are the auth related urls which are
things like login and log out
things of that nature so that's more of
a security thing
that's built into django so we're going
to take advantage of it
and then we go to our pages we have our
home page which is just going to be
our our default now so if we don't give
it a if we just go to the
site it's going to jump at our to our
home page
sites which is going to be our ability
that's going to be a list of the sites
that we've entered
we're going to be able to edit a site by
giving it an id
we're going to add a site if we don't
give it an id and then we're going to go
to
we're going to have a youtube user
registration page
and so those are our urls and so now we
have home page
list sites edit site ad site and user
register that we have to build out
in our views and so as we flip over to
our views
um a lot of this stuff is going to come
um as we go
so there's a couple of these i can
actually eliminate out i don't use time
zone
um but i'm going to leave these in here
anyways for right now
and this would be stuff that again
you'll get the code and you can
fairly quickly i think you'll see what
you need and what you don't need
and like i said chango is pretty
friendly so when you try to run
something and it doesn't
see something it's expecting it will say
hey i can't find
you know such and such a library which
usually will imply that you then need to
go
and import that library you know or do
it from
now home let's just sort of walk through
our pages from the view point of view
um i'm going to come back we'll look at
some of these html things here in a
little bit
this is the the logic behind it so for
home page
uh we're going to come in and we're
going to see if the user is logged in
if they are we're going to go to
welcome.html
so they're going to get a welcome page
otherwise
i'm sorry if they're not they're going
to go to the welcome page if they're not
logged in
if they are it's going to go to the list
of sites
and notice one it's going to render so
it's going to
actually it's going to say all right i'm
going to kick over and render the html
page
this one says instead of going to slash
you know just slash as your home it's
going to redirect me to slash sites
which is going to go to the sites page
so i'm going to if i start here
and i'm logged in it's going to redirect
me to sites so it's going to go to this
list sites call and that's just behind
and just within this it's going to do a
quick redirect and now i come into list
sites
so we take a look at that one which is
sort of our it's our home page for
people that are logged in
um if they are authenticated in this
case if they're logged in
so if they try to go to the sites page
and are logged in
then it's going to get all of my site
objects or site records out of the
database there's no filtering
i'm going to set up a parameter of sites
which is all that list of
all records and then i'm going to render
the site list and i'm going to send it
parm the parameters which happens to be
the list of all sites if i'm not logged
in it's going to tell me to go log in
and i can see that here
i think i am logged in
so if i go to sites
it takes me to uh my sites if i log out
and go to the same thing then it's going
to take me to
my welcome page and we'll take a look at
how these things got built out
here in just a minute so that's list
sites
another page i'm going to put together
and notice i just kept all these secure
from the start so if you're not
uh let's see if you're not logged in
it's going to send you to the login page
so all of these
um if i try to go to like
site then it's going to ask me to log in
if i try to go directly to any of those
and then i can log in
and get it so i've real quickly i mean i
didn't have to
really build much to this is just this
accounts login if you remember that was
included from the auth
piece here whoop sorry accounts
and then i added all of the auth urls so
one of them is account slash login
and so i go here and i can see that
that's my login
so once i go for edit site that's going
to take
an id this is the only one that's taking
a parameter so it's going to be
so if i do site slash one and this is a
node
this is with the slash it's not a query
string parameter
so for example um if i do site slash one
that's going to try to get me something
and it does not exist i don't have any
sites right now
if i do it as a query parameter that's
different so i'm not saying
id equals one
in that case it's going to
think that i didn't send anything so
it's going to try to add a site
because that's not a that's not a query
string parameter that's an actual
part of the url that we are addressing
here since if i just give it a query
string version then it thinks that it's
this because it gave me cite plus a
query string
so edit site if i give it an id it's
going to say it's checks to make sure
if it's not not zero so if it's not a
if it's an id that's not zero then it's
gonna go try to find the data for that
site
uh we saw what happens if it doesn't you
get a you know four one says hey i can't
find that
uh otherwise if it's a zero as an id
it's going to create a blank record
so which basically works identical to ad
but we just i did it this way so it's a
little more
uh ponderous approach if we post to this
site
so if i'm doing an update and posting
then i'm going to grab the data from my
form
and um i'm going to see if my form is
valid and then i'm going to go ahead and
save
and then i'm going to once i've saved my
record i'm going to go back to my list
of sites
and we'll take a look at this in action
a little later here
so i come through for edit i will create
a
blank form which i did here so it's from
site form and we'll take a look at those
in a minute
i'm going to send my id across and then
i'm going to have a title for the page
that i'm going to use
and then this is going to call
siteedit.html
for add site it's very similar i still
call site edit
basically the only difference is i just
come in and
create a blank form i don't ever
do the here where i'm trying to grab
an object from the database based on the
primary key
and so um two other things
i went ahead and i've created a logout
that i can call
and the user registration
user registration is so we can actually
create a user within our
application and that's a form that we'll
take a look at we've got a registration
form
and there's a registration html that's
just some additional
administrative pieces you really don't
need to log out the register
or even to check the authentication you
could just say i'm just going to let
whoever hits this application see
everything
so i built these
and one of the things i want to do now
is go for my views is we've
referenced these forms all over the
place forms
are the application version of
the model now i've got a couple forms
that i'm
i'm basically stealing from django which
is user creation form
in user and those are so i can do the
registration
and the user login so that gives me a
really easy way to
create and administer users those
pretty much you're just going to use
what you you know what comes you can see
there are
certain fields that you can require or
not you can make some tweaks to it but
that's sort of outside the scope of what
i want to cover this time around
i do want to look at my primary form is
the site form
and within that it is based off the site
model
sites model and i'm going to give it my
list of values that are going to be on
my form
for each of these i'm giving them with
labels i'm going to give them sort of
some pretty
labels for them and we'll see these in a
minute
and then there's some widgets that i've
got here to allow me to do
input most are pretty simple i've got
text where i'm limiting the size
and i'm giving it a class this is a css
class in case i wanted to play around
with that
um and then i've also got a text area so
text input
single line text area i have uh
multiple rows here i've got so i'm going
to do two rows of 80.
it probably should actually be three
rows because i have a 250 limit on that
one i think
and then um that's pretty much and then
a number input so
those are my forms and so now
i can go to uh let's look at our views
let's take a look at the the html side
of this
um there's two things one
first we're going to have a we're going
to add a static folder
which has to be addressed in settings
and that's where we're going to put uh
like our javascript our css
images things like that so those will
all go in our static folder
and then by default we get
a static url and then
and all we have to add is that our
um where our static files directory is
so i'm calling it static so it's just
off of my
off my base directory for my application
with static this os path join
is a operating system
generic approach to adding combining
values to give you a path for the
uh the hard drive for the you know the
local drive
so it takes care of things like you know
backslashes versus forward slashes and
things of that nature
and again this is stuff where you not a
whole lot you need to do other than just
know that it's out there
and once you've got it you know once
you've googled it you throw it in there
and boom
you know you're ready to go now within
my static
i pulled down the bootstrap files i
think we've seen this before so i'm not
going to
go dig that up and this just happens to
be because i'm going to use bootstrap
i do although i don't need to use this
blog guy
i'm not actually using him anywhere so
i'll just move him to trash
within the css uh one of the things that
bootstrap gave me is the form helpers
javascript monitor css is my application
and then i've got these images in case i
need them
now static comes in use when i go to my
templates
so templates is where it's going to look
for html stuff
so when i go to you i'm sorry a view
and i look and i say you know create
register.html then it's going to try to
look for that within
the templates folder and so i have
site edit which i've created here
and now with each of these so let's
start with our welcome
uh it extends base.html so this
this is built on top of base html which
i'm going to look at in a second
if you remember we have blocks
and so we have this content block that
is going to be
part of this html before the block
that content block it's going to go pull
in
base html base html is
our generic format for a page
we're going to load the static files so
everything that's within that static
folder
we load it and then a lot of this
is like here static we're going to pull
in our bootstrap stuff both the css and
the javascript
um we've got the form helpers one we've
got some jquery javascript that's pulled
in for bootstrap
pulls in another little javascript and
now we pull in at la one of the last
things we do is
and all of these are sort of your
standard uh link for a style sheet
h reference and then i'm gonna give it
uh within stat
uh within static css
monitor gives me whoops and i just
accidentally hit that
pulls in my my css i create a header
which i'm using
this is a pretty standard bootstrap
navigation in effect it gives us this
little thing here
which also is responsive so as i shrink
it down it gives me my little
hamburger menu so i do that to give me a
nice little responsive interface
uh let's see i get my i set up my menu
items
which is just basically a home and then
if you're logged in
uh i've actually i'm using some it's
still pi uh django so i can say if the
users log in if they're authenticated
then i'm going to allow them to have ad
site and login i'm sorry log out
if they're not authenticated then
they're going to be asked to log in so
they just get home and log
in so if i log out i just get home and
log in
if i log in i get home
add site and log out
and then i have my content block
and i'm wrapping that in a div that's
going to be of class content
i'm going to see that with our style
sheets a little bit and then i have at
the bottom
i have a footer which is going to be of
the standard footer class
and i've just got some basic text for
that at the very end
pull in some additional uh javascript
which i think didn't already have that
one bootstrap yes i did
i pulled in some javascript that i
actually pushed that stuff to the bottom
just for speed and so it comes in at the
end and then
finally comes in and pulls in javascript
that it needs
so that gives me our base so i've got a
footer i've got a header
and then i've got my content so if i
look at welcome
there's a header up here uh this content
block and then there's going to be a
footer underneath it
my content block i've just got i've got
javascript included here which is very
simple
for my on clicks so i can log in and
register
i've got a little text and so
i can see that right here uh oh i'm
sorry that's actually not it this is the
welcome
so i can see i've got my login button
i've got my
register with the site got login
registered the site register
i did not have one of my templates set
up so we're not going to look at that
right now
oh i'm sorry i can check i can fix that
real quick
it's not called external it's called
base
and i think that will give me all i need
so now
yeah so now i can do user registration
so i could add a user if i wanted to uh
it gives me some help for each of these
what is it
you know as far as your username your
password
and it's a very straightforward uh here
let's see so i do
if you guys remember uh i bring in the
registration
form and let's go look over here real
quick
for user register so i'm using this
registration
form which i pass in i pass the form
as form is the parameter
i'm going to pass that into register dot
html
and so i can come in on the register
side and i can do a form
and i can either there's three ways i
can do it i can do it as a list
as an unordered list as paragraphs or as
table
if i want to do a table i can change
that real quick
and it's going to be a series of rows
if i do that as a registration now it
looks more like a table
i get to the end after the table
if you remember i have to send it a csf
csrf
token because i'm going to be if i'm
going to do data entry stuff
and then i have my submit button
and then i've so i've put this together
and i've also got my little helpful text
you can also log in if you have an
account log
in bam bam and so i
i built my header which is the
navigation i've got my footer
which is down here which is also very
straightforward
and then this is my content now you you
may see that i've got my nice little
coloring for that that i picked up with
my
css uh monitor
if you remember i used a class content
for that main block and so with each of
those
i've just come in and i set a width
which is 90
i have it centered basically because
it's got a padding to the left
of 5 so it just kicks it over five
percent
i also take the text within it and push
that over five percent
and then i've got my background color my
forward color and then my height
is just eighty percent so it just sort
of limits it so it's a nice little small
screen very
uh you know early 90s look and it's also
responsive so doesn't look too bad as it
shifts stuff around
now uh that is so if i want to add a
site
so that's my welcome site list is what
i'm looking at here this one's a little
more complicated
um i've got an if here so if the user
has a first name then it's going to say
sites for that user otherwise it'll say
my sites
and then i've got my add a site button
which just takes me to add site which is
right here otherwise i'm going to say if
i have
let's see so if sites which is if you
remember that's a list of the records
from the sites table
if that has some entries then it's just
going to be a force of foresight
insights
so for each record i'm going to call it
site and then
i'm going to come in and build out a
listing of those which we'll see that in
just a second
and then i do an end for if i don't have
any then it's just going to say no what
sites entered which i have here
click on add a site to get started
and we'll take a look at this second i'm
i've got each of these displayed
there's going to be a css class site
which we're going to look at in just a
second so let's create a site
and this again oops let's look at that
real quick create a site i'm doing a
form as table
and i use that site form that we use
here
so i'm going to see site name
description test url ping type
blah blah blah i'm going to see all that
kind of stuff so i'm just going to it's
going to display
that out i set the table or the title
which is either add or edit
and then i've got a save changes and
then note
i've also got my csrf token so i don't
have to worry about
cross-site issues so i'm going to add a
site
i'm going to do it this is the dp
homepage
heartbeat
the ping type and i just had a couple so
i'm gonna do a heartbeat
uh the test url is https going back
slash
developpreneur.com
desired type is uh going to be is alive
desired value don't have to worry about
that because if is alive it's just
going to be a response uh and i'm going
to do this
every five minutes and so i'm gonna
that's my
heartbeat check when i do save changes
now i could see a list of sites
uh which is whoops site list
and so here this is where it's going to
for each record within there it's going
to do
an md5 and an md1
which we can there we go as it gets
smaller the 5 is actually
because of the size of the screen it
gets funky pretty quick but
normally what i'm going to see is if i
have multiple rows
let me add a second site let's see
i'll do my this one real quick
i'll do the same thing i'm going to do a
heartbeat
calm i'll go straight to that page
simple response well it's gonna be is
alive
don't have to worry about that and do
that once an hour
save changes so now we can see two sites
together
each of these i've cleaned these up a
little bit and
i can either edit or nope i didn't have
an on click so if i want to edit one
then i can come in and i can edit that
page
uh from this so let's take a look at
from the uh
the css point of view uh because that's
this is something we wanna we're gonna
wanna play around with a little bit i
think to make our applications more
useful
and because of the power that uh django
gives us
it makes it pretty easy for us to
you know clean this stuff up and well we
can use css anywhere
apologies um
so here i'm sorry so we're going to go
over our css and we want i wanted to
step into this a little bit just because
we haven't spent much time on it
so if we look at our what did i call
that i call
that site
so here's my class
and i can do quite a bit with this as
you can see this is a
mother moderately lengthy
css entry and i and with this i'm doing
things like i'm setting the radius we
can see i
as i hover i get my little background
it has a sort of beveled kind of look
and i found the easiest way for us to
play around with this stuff
is actually through pretty much any of
your modern browsers
if you want to change a look and feel
then you go up here so like
here i'm selecting it's hard to see i
know this is very small text but
i'm selecting this item so i'm going to
select
a site and then over on the side i'm
going to be able to actually see what is
the css that's being used
and i can start playing with this live
so i can change my background color
let's say
instead of that gray i want it to be uh
red yeah that's so that's pretty ugly
but
you know i could say instead of the
text color the one that it was
i want to change it to be oh i don't set
the color
uh but whoops
let's see if i can add a color real
quick uh shoot i can't because
okay there we go there we go so now so
if i do color
uh white then i can change that
um i can also change around my padding
so i can go from
25 to 30.
or i can drop it to nothing and see that
now my padding has been moved over
i can work with my margins
so i've got a bottom margin here i've
got a little bit of space
i could get rid of that i could start
cranking up the
uh and within the padding so now i can
like really tighten some of this kind of
stuff up
i could increase the font i
could decrease the font uh whoops
that's not decreasing the font that's
decreasing the font
and then the the quick way to play
around this stuff is play around with it
live
and then you can just copy and paste and
just take all of that copy it out of
there
flip over here and i could make that
part of my css and boom i'm off and
running
now that that hits i know we haven't
gone too deep into this but that does
give us at this
point uh an application
that we're entering some stuff i've got
some basic css we'll talk about this a
little bit more
uh in a future session we can enter some
data and that leaves us
the next time we come around actually
with this with this information to build
a back-end that actually is going to do
these checks based on pings and things
of that nature
so what have we covered we went through
the basic app
creation uh actually basic project
creation
and that included creating an
application with it we looked at forms
we looked at our model
views urls went through some nice basic
stuff
put our application together that way
looked at setting up our css and
actually including that in
and it's again much like any other web
application you're using the same kinds
of
commands it gets down to its javascript
and html
i talked a little bit about some
troubleshooting kinds of things as far
as you know being
having debug turned on and being able to
play around with that
and using our django environment for
things like
um backing up our data
and importing it into others um of
course doing our migrations and things
of that nature
so questions and comments
yeah i just uh i wanted to say it's all
more reason
i'd love to uh see if you see if i could
use this um
you know django to to monitor one of my
apps maybe not
write the code in in python but
um uh you know do some monitoring and
just uh basic operations what you've
shown here
uh in django just for how easy it is to
set up that's awesome
yeah it's definitely there's a as a
uh an ancillary application it is
actually a really
solid solution for that so when you
and i know you you've spent a lot of
times building you know like utilities
and things like that those applications
and
and uh little executables and that that
we have to build
or we don't have to but we usually end
up building
because we want to be more productive
because there's things that we find
ourselves doing all the time and we want
to automate the task or simplify it a
task or
do it in a way that's somebody that's
not us that doesn't have maybe the
the deep knowledge of the core
application that they can
do stuff that they can you know do some
administration or do some reviews or
reports or things like that
and uh the more i play around with the
more that i find that both
the python itself and because of it's
so lightweight and so uh
pervasive as far as environments and
things like that
uh and then django if you want to an
interface for it
it's a really good pairing for doing
those kinds of applications
so good point glad that you you're
seeing the usage as well
other questions and comments
if anybody's talking they're on mute
otherwise go ahead and move forward
so that brings this session uh to a wrap
i
had hoped to get further into it but
just as i started looking at it and some
of the things i wanted to cover
this is definitely going to have to be a
multi-part session
we've done we've got the bulk of it
we've got actually a very
we have a functional front end i think
this would count for like a
minimally viable product from the front
end point of view
uh we'll do a little bit of tweaks to it
and then we'll come back and swing
around to the back end uh next time
around
as always i want to appreciate your time
thank you for you know listening in for
checking this out for
comments and everything else if you have
any other questions or anything else
that you need to contact us
you can always catch us at email info
developer dot com
you can go out to the contact us form on
developernoor.com
we have a youtube channel that you can
go if you go
look for developpreneur from youtube
then you'll find it
and you can subscribe and we put stuff
out uh twice a week
tuesdays and thursdays right now we've
been a pretty steady schedule for the
last year so i'll probably maintain
vimeo is not um
not as frequent as what we've put out
from the youtube side
we more often will put things like the
these mentor classes will show up at
vimeo first
and then eventually they'll show up on
youtube
and then uh if you want to keep us from
the podcast point of view you can always
check out the better developers podcast
or develop an order podcast
it goes by both names for example if you
have alexa or something like that say
you know alexa enable better building
better developers
and it'll start playing the latest
episode and just
some of the ways we have to communicate
to you guys and
ways for you to communicate back to us
as we work together to try to make
every developer better so go out
have yourself a great day
[Music]
you
Transcript Segments
0

[Music]

20.08

so

20.96

starting into this one um

24.24

i do this this is a python django

26.16

example i want to build an application

28.08

when all is said and done

29.599

that is a essentially a standalone that

32.079

you could sit down

33.04

walk through this code have a pretty

35.36

good framework for an application and

37.04

then

37.68

extend it as you need i'm going to try

40.719

to make something that is

42.399

moderately useful for everybody

45.6

and uh something that you can get there

48.48

are better tools for it but if you want

50

a quick and dirty solution

51.36

then this would be it um

56.079

what we're going to talk about today i'm

58.48

going to get as far as i can

59.92

i don't think we're going to get really

61.68

into

62.96

implementing all these pieces but we'll

64.559

talk about them so

66.08

this is from scratch we're going to

67.6

create our application uh

69.439

and talk about getting that in the

70.84

database i'm not going to code as i go

73.52

too much i'm really because it is a

76.479

somewhat fair amount of code it's

77.68

probably a couple hours worth of code

78.88

that was

80.08

that we're going to look over but i'm

81.6

going to walk through it

83.439

and talk about some of the key uh things

85.6

that you know decisions and

87.119

how we get there and then of course

88.799

although i don't have it right now

90.56

uh afterwards i will put it out in

94

having a public github somewhere so that

96.4

uh you guys can take a look at you pull

98.079

it down and play with the source code

100.24

to your desire so we'll create the

102.56

application

103.759

focus on the database model in the

105.2

background set up our screens

108.079

tie the screens to the model and then

110.72

we'll talk a little bit about the

111.68

backend process but we're really gonna

113.92

those last

115.04

couple items we're really gonna flesh

116.56

those out more in another session we're

119.04

just gonna

119.52

try to set the table where we can for

121.52

some of this this time around

126.64

so start with the application the

128.56

database

130

um we're going to call this monitor

133.12

and uh it's name of the application uh

135.52

you can call it whatever you want

137.68

but uh what we're going to do i'm not

139.92

going to show this

140.72

i'll show you sort of the results of it

143.28

although we could

144.239

i'll probably run this one real quick

145.599

anyways with a different name

147.599

but the way we start as and we've done

149.68

this talk about this before the way we

151.28

start a django application

153.92

once it's installed and we have examples

156.8

of that elsewhere so i'm not going to go

158.239

back through that again

159.44

but once you have django and python in

161.04

and ready to go then you just run django

162.879

dash admin

164.239

start project you give it a project name

166.959

and as you'll see it's going to it

168.56

builds out some

169.76

some structure a folder and things like

171.76

that so you're

173.04

off and running you're essentially ready

174.56

to run an application right then you

176.48

could

177.36

from there start and it'll spin up a

179.2

little app for you

182

we're gonna focus in on since we're

184.879

going to the

185.599

the database first we're going to tweak

188.239

the settings because we're going to go

189.599

from the

190.319

default uh sql lite that they have built

193.599

in with it we're going to flip it over

194.959

to a

195.84

mysql database we're going to point to

198.4

that

199.92

we'll talk about creating the database

202.319

and a database user

205.12

set those guys up in the settings and

207.519

then do a you know basic connection to

210.84

it

212.08

now stepping back the application itself

215.36

is going to be well actually i think i'm

216.959

going to talk about the application as i

218.319

look at the model that may be

220.319

a little bit easier way to look at it

223.519

so let's flip over

228.64

and let me do this let me take

232.799

one of these

236.48

and actually go with this one and i'm

239.28

going to blow this up a little bit

241.68

for this first little bit

247.12

and pull this up a couple more times

249.36

there we go

254.159

so the first thing i talked about is we

255.519

can do if you want to create one is you

257.519

do a django

258.32

admin uh start application

264.32

and give it a name so i'm just going to

265.52

call it monitor 2 for now

269.28

oops sorry it's not start application

270.96

start app

272.88

notice django actually this is a nice

274.56

little thing django's pretty friendly

277.36

um and i've seen a couple other things

280.08

like that i think ruby does this as well

282.4

where it'll help you out a lot of times

285.52

here did you mean and so it's like oh

287.68

actually yes i did mean that

289.04

so it sort of guesses its way into stuff

291.52

so now

292.56

uh i ran through that and if i go to

295.68

monitor 2 then it just created this

299.68

monitor 2 database

301.12

and then it created an admin apps

303.759

migrations models test views

306.24

and if i look at migrations

310.08

then there's there's really nothing in

311.52

there but it at least starts with that

312.96

very simple structure and so i actually

314.8

can go in here

316.8

as i mentioned uh let's see

322.84

whoops i miss one here

329.68

did it

337.12

did i miss a phone somewhere

341.199

oh wait well interesting it did not

344.24

build normally it builds a manage.py

349.36

and i'm not sure why i didn't get it

350.96

this time let me check real quick

354.56

start project oh i'm sorry it's not

357.199

startup it's a project my bad

361.759

so i didn't mean startup i meant to

363.6

start project

365.6

let's do rf

368.72

monitor 2 this is why i tried not to do

371.199

too much

374

coding

379.039

we talked a little bit about apps before

381.759

within a you have projects then within

383.52

those you can actually have application

385.039

multiple applications and so

387.6

at this point i've got a project and it

389.6

builds by default

392.84

the an app with the same name as the

395.68

project but i could actually add

397.52

additional things which we may look at

399.039

at some point where we would do maybe a

401.28

a front end a backend an api things like

403.919

that

405.039

but now i'm gonna keep it simple so once

408.24

i've built it

409.919

it's it's built a you know fairly simple

412.96

couple things it's got some settings

414.56

some urls

416.56

not a whole lot that it's built but i

418.16

can go in and i can do

419.759

a run server

423.68

and it's running it's going to tell me

425.759

there's we've seen this for it's going

426.96

to tell me if there's some database

428.08

migrations because i have not set up the

429.84

database

430.96

but then if i go out here somewhere

437.52

then i can see and i'll pull this up a

439.44

bit i can see where

440.8

okay it's you know i'm running my django

443.84

server

444.319

it's got links oops let's put this here

447.599

like this a bit and it's got links so i

450.8

can learn some stuff about

452.24

django if i wanted to or you know for

454.24

here this is just basically say hey i've

456.319

got this built so now

461.039

i'm going to flip over to some code here

463.759

so one of the first things we want to do

466.319

is we have to create our database

469.599

and if i can find where i put here we go

472.96

so one of the things is first thing i do

475.28

is i'm going to call this

476.4

database monitor and

479.52

this is a little bit getting into the my

481.039

sequel side of stuff but

484.08

um just so you know it's creating a

486.319

database is very simple you come in log

488.16

into my sql

489.44

say create database name the database

491.68

boom done you have a database

494

it's like any tables really of use but

496.16

yeah you've got a database you can work

497.759

with

498.4

uh in this case i actually go in and i

500.16

create a user and this is

502.96

got a nice little case issue there um

507.68

i created a user for this database and

509.44

i'm just going to call it uh

510.8

mon owner for the monitor owner and i

513.36

give them a password

515.599

and i need to do it i'm going to do it

517.12

for whether i'm on local host

518.959

or you know if it gives me if recognizes

521.519

me by some sort of ip address

523.68

and then i'm going to grant all the

524.72

privileges and so what this does here

527.6

is um creates this user mod owner

531.279

and then i get all the privileges that i

533.519

need to be able to administer

535.6

the monitored database so if i wanted to

538.64

jump

539.04

over to

545.12

my monitor database oh actually i can

547.279

say so here

549.279

so once i create it i'm going to log in

551.12

as mod owner

554.32

and then i have the monitor database and

557.04

i'm able to start working with it

559.2

so the first thing i've got to do

561.04

because i'm going to

562.64

not use the sql light that django

564.8

provides

565.68

is i have to make sure that there's a

567.04

database i'm going to connect to django

568.8

will not create the database

570.959

that has to be there and i need to make

572.64

sure i've got a user because

574.64

once i have my user and password that

576.08

allows me to connect to that database

579.519

in order to do so i have to jump into

582.72

the settings

586.08

in which um let me do this real quick if

590

i look at monitor two

594.16

monitor two um there's gonna there is a

597.839

settings that is already that is

599.68

generated

600.56

from start uh some of these files we're

602.32

gonna talk about actually we're going to

604

we create them uh they're not created

605.839

from scratch but just

607.04

so you notice this is one that is and

610.16

most of this information

611.519

is in here there's a lot of as i talked

615.04

about the django

616.839

friendliness there's a lot of comments

619.279

around what are we doing how do we set

621.2

this stuff

621.76

up what do we need to do

625.839

and with our settings right now

630.64

the first step we're going to do is

631.76

we're going to come down and we're going

632.72

to find a section on database

635.839

and by default

640.079

let's look at this real quick

646.24

default this may be a little hard to

648.16

read

649.279

uh but by default the engine is going to

650.8

be sqlite

652.959

and it's going to connect to a little

654.079

sqlite database which you can see

656.72

i think it actually creates it somewhere

658.64

in there

661.76

or maybe that's when yeah so it's

663.92

already created a little

665.519

uh database there the sql wipe

668.56

so that you can actually work with that

670

you can if you didn't want to use my sql

672.64

you could go right in and you could

673.92

start using sqlite

675.279

right away we're switching gears a

677.2

little bit and so what we're going to do

679.519

is we're going to come in and set it up

681.12

and say that we want to use the mysql

682.8

backend

684.24

we give it the username of what or the

686.079

name of the database the name of the

687.519

user we're going to connect with

689.12

and the password there is as part of

692.48

setup you may have to install using pip

696

which we've talked about in the past you

698.079

may have to install the mysql client

701.04

we covered that in previous uh

703.44

discussions so i'm not going to

704.88

you know rehash that and then once we've

708

done that

709.36

then uh as that being once we've set up

712.16

the database and connected to it

714.72

so we can connect to it then all we need

717.04

to do and i'm going to do this

718.56

in the monitor two sense just to sort of

721.36

see it

727.36

is then we can come in and all we do is

728.88

we do a python run it against manage

731.76

and we can do make migrations

735.279

i'm not sure if it actually and then we

736.959

give it the application name

739.2

or project name

742.48

uh whoops oh and

745.839

it's going to say no installed app

747.279

because the one other thing we have to

748.56

do at this point is we have to add our

750.88

application to installed apps

753.68

for some reason when it creates one it

755.2

doesn't do this but this is going to be

756.639

your name

758.16

your application name so here i would

761.279

have to

762.88

go into the settings for monitor 2

766.8

and change it over so i'm not going to

768.24

mess with that too much because i want

769.68

to get too deep into the code

771.6

but what we'll do is you do make

773.519

migrations and so let's flip over to

776

monitor

779.519

if i can pull that code up a little nope

781.36

i can't blow it oh

782.639

there we go let's blow that up a little

784.079

bit more

785.92

so in here i can do python

789.6

3 if i spell it right

793.12

python 3

796.56

manage if i do make migrations it will

799.36

go through

801.279

and make some but there are no changes

802.72

detected because i've actually run this

804.56

and then you can do migrate so in your

807.44

case the first time through

809.12

there's not going to be much there

810.24

aren't going to be any migrations the

811.519

first time we're going to make our model

813.68

and then we would run make migrations

815.44

and then we run migrate

816.88

and it's going to up it's going to

818.8

update stuff

820.399

in this case i can see where there's

823.68

this admin auth content types and

825.839

sessions those actually all are supplied

828.32

by django and then monitors my

830.959

application itself

832.079

and i don't have any migrations at this

833.92

point

835.6

so if we were to run all of these then

838.24

we would be able to run our application

840.079

and we wouldn't get that warning that we

841.68

got

842.16

way back here that said um

846.959

go back here oh i'm sorry it's over here

851.519

we wouldn't get the little warning here

854.959

that says you have unapplied migrations

857.199

so if i run it on monitor two

859.44

where i just saw that i don't have

863.6

uh migrations that haven't applied then

866.399

i just get a straight

867.6

you know it checks a couple things gets

869.12

itself set up and then boom

870.959

it's running so let's go over to because

874.399

we're focused on the database let's flip

876.079

over to the models

878.16

and let's shrink that down a little bit

882.639

now models is one um

886.959

let me go back to here

893.04

that is not included so you know when

896

it's first

897.04

built we're going to have to we'll

898.399

create this models.py

902.72

and it's one of these names that it's

904.639

going to be looking for

907.279

i think we may see it here i think

909.68

there's a note on that somewhere

911.6

oh no it's not in here so we're going to

914.639

go in and models is

916.399

basically where we're going to source

918.639

our information for our database

920.639

as we saw when it attempted it there was

922.48

a couple different

923.76

applications auth and things like that

925.6

that were supported by

927.279

provided by django well this is what

930.56

we're going to provide with our

931.6

application

932.32

so models.py within an application

936.24

is the model for that application

939.519

so one of the things we have to do is

941.04

we've got some imports we've got to do

942.72

from the start

944.72

and basically this is django db and the

947.04

contribute

947.839

models actually really you just need

951.6

import models but what we're going to

953.759

find is that

954.959

when we start using if we use security

957.279

or if we use

958.959

well really it's security stuff or if we

960.56

have dates we have to import some

961.92

additional

962.639

pieces so i have those up there but

965.279

really this first one is what matters

967.44

because we're going to see every one of

969.6

our models

971.04

if you remember this is how we do

972.24

inheritance so this lkp

974.8

ping or lookup ping inherits from

977.399

models.model

979.6

and that tells the system in the back

981.6

end that we're going to be creating a

982.72

database

983.44

based on that now what we're going to do

986.48

in this case is we have one and this is

988.399

where i'm going to start talking about

989.36

the

991.68

application itself that we're building

993.44

this time we're going to drive this off

995.36

of one primary table

997.04

and it's sites and what site

1000.32

what a site is what an entry and a site

1002.24

is it is a web address

1004.32

uh could be a site could be as far as

1006.399

like a website it could be

1008.399

an api address it's just pretty much

1011.44

anything that we could

1012.639

you know any url so it may be a straight

1015.759

uh address it may have a a port number

1019.04

it's whatever it needs to be and the

1021.6

reason we're going to provide that

1023.519

is because we are going to have that as

1025.439

an address

1026.64

where we can do some sort of a

1029.439

essentially a heartbeat a heartbeat or a

1031.36

ping or something like that

1032.64

of that site to see if it's up and

1034.079

working

1035.919

now the reason that we've got you know

1038.72

so we're

1039.679

talking about these columns now in these

1041.28

fields so each site we're just going to

1043.6

have

1044.24

which we just sort of talked about we'll

1045.679

have a name a description and a a link

1048.4

i don't have that image like that

1049.76

shouldn't be there i thought i got rid

1050.88

of that i'm sorry we're going to call it

1052.88

a url

1055.6

so we have a name and description and a

1056.96

url and this is

1060.24

so we can identify what the site is and

1062.72

also

1063.36

this address so that we can reach it now

1067.2

note that we have uh character fields so

1069.52

name and description are just

1070.799

they're just text you know one's uh 50

1074

one's 250 so the name we're going to

1076

keep it sort of small

1077.44

and the description we're going to let

1080.799

it get a little bit longer

1084

and then the url we're actually making

1086.16

this a url

1087.28

field and so that tells django that it's

1090.16

something

1090.72

it's got some additional validations and

1092.48

things like that i'll try to get that so

1093.6

it doesn't

1094

pop up it's going to do some additional

1096.4

validation

1097.2

and have some basic widgets and things

1100.08

like that that we can use for it

1104

last check is just a date and within

1106.799

that we are going to

1108.4

that's the last time that we did a check

1109.84

so we're going to you know do periodic

1112.24

heartbeats essentially

1115.36

and ping is going to be um

1118.4

this is going to be a lookup we've got

1120.24

three lookup tables

1122.48

in each of the lookups i guess i'll jump

1123.84

to that real quick we're keeping very

1125.6

simple they just have a code

1127.36

a name and a description really the name

1130.48

is user friendly

1131.44

the code is essentially going to be the

1133.12

primary key

1134.48

although each of these has an id field

1137.039

in the background

1138.4

uh we're going to use this code as our

1140.72

primary key for looking up values

1143.28

and instances records within each of

1145.52

these lookups

1147.6

and we have the ping which is

1149.12

essentially what type

1151.52

of uh heartbeat are we going to do is it

1154

just a get

1155.12

is it a ping is it a git where we're

1158.16

going to actually check the value

1159.6

the responding value uh it could be a

1162.08

put you know something like that so

1163.679

we've got to we're going to have a

1164.64

couple things that we're going to be

1165.6

able to support

1166.799

we'll start with very simple and you

1168.559

know we'll be able to extend as we need

1170

to

1170.799

result is what kind of result we're

1173.52

looking for

1175.919

and this gives us essentially a type

1178.799

that will be easy for us to check

1180.4

against

1181.679

so that we can say whether it's a

1183.28

failure or not so the result could be a

1184.88

failure or it could be that uh maybe we

1186.96

got a 200 code or a

1189.2

400 code or a some sort of a value

1193.12

return back and then we can also check

1194.72

that value to make sure it's the right

1196.24

value

1196.88

that was returned and then frequency

1200.559

has to do with how often we're going to

1202.32

be able to do that we're going to want

1203.44

to do these heartbeats

1204.64

we could do it a certain number of

1206.64

minutes a certain number of hours

1208.24

certain number of days

1210.799

and so if we look at so that's

1213.919

our ping is our type is how are we

1216.799

testing to see that what are we doing to

1218.559

verify that this site is alive

1221.2

essentially

1223.039

we have a desired result which is

1226.08

basically saying what you know what

1227.6

results should we be getting back

1230.32

it may be result value as well so maybe

1232.4

we get a 200 as a desired

1234

result but you know or essentially what

1237.36

we're going to call

1238.32

uh whatever we name that but there also

1240.4

may be a result value so for example

1242.559

a an api call where maybe you send it a

1245.44

specific

1246.4

call and it needs to send back a

1248.64

specific value or string or something

1250.72

like that

1252.559

and then uh so frequency type and

1254.72

frequency is

1256

you know are we going to do this we

1257.12

checking every minute or checking every

1259.12

certain number of minutes certain number

1260.799

of hours certain number of days

1262.72

and then the frequency is that number so

1265.12

if my frequency type is minutes and my

1266.96

frequency is five

1268.08

we're going to check every five minutes

1269.76

and i've just got some basic audit stuff

1272.799

of when the record was created and when

1274.48

it was last updated

1277.12

most of these we've covered in the past

1279.919

we have foreign key relationships for

1281.84

those lookups

1284.88

most of this is text we do have a couple

1287.039

of dates

1289.28

and some integers but nothing terribly

1291.44

interesting here

1292.559

we do have our url field and then all of

1294.96

our lookups are

1296.559

essentially identical um maybe note that

1300.08

we have the

1300.96

uh two string we do this because these

1303.28

are going to since these are going to be

1304.32

lookups

1305.76

when it does a lookup the

1308.96

value that we see in a selector is based

1311.6

off of this

1312.64

the string function so we're going to

1314.48

make sure we go off of the name

1316.32

as opposed to the code or the

1317.52

description uh description could be very

1319.679

a bit lengthy for a drop down uh

1323.76

and so and then in the the site itself

1326.08

if we want to list the sites we're just

1327.36

going to go by the name we're just going

1328.72

to keep that very simple

1331.28

so that's our model and then we can go

1334.32

in

1334.799

uh we once we've built this out then we

1338

would go in and do our make migrations

1339.84

and then

1340.32

migrate and at that point

1343.36

we will get a database um

1346.48

i don't know if this is yeah i can't

1348.88

blow this up too much

1350.799

but hopefully you can see here

1353.84

uh within this if i can go let's just

1356.24

flop

1357.44

i'm sorry i can't get this any bigger um

1360.08

but essentially what i've got here is

1361.28

i've got a list of tables that it

1362.559

generated

1363.919

i can see uh

1366.96

remember i talked about that auth

1368.32

application well the

1370.32

table names if you in case you have

1372.24

forgotten the table names are prefixed

1374.32

by the application name

1376.4

so these are the auth related tables the

1378.24

ones under uh auth underscore

1381.039

i've got the django related ones which

1383.12

is uh the admin and the session stuff

1385.679

and then monitor is my monitor is my app

1389.36

and i can see where i have my sites

1391.919

table

1392.88

my lookup result lookup ping and lookup

1395.44

frequency

1396.64

and actually since i did just delete

1399.84

uh i did delete a column out of this

1403.44

in my model let me make sure i

1406.48

saved it we can actually that gives us

1409.919

an example to play with a little bit

1412.159

so now i can go in if i do make

1414.84

migrations

1418.48

then it's going to go in it recognizes

1421.279

here that i remove that field img link

1423.6

from sites

1424.72

and then if i migrate

1428

it's going to execute that

1431.679

and so it applied this monitor remove

1434.4

sites image link

1435.52

and if we look over on we've got a

1438.919

migrations

1440.799

folder and we can see each of the

1443.52

migrations so i can see here this is my

1445.52

initial

1446.559

so i came in and it created the model

1448.4

for lookup

1450.159

uh frequency ping and result created my

1453.52

initial sites table

1455.279

and then i came in and i tweaked

1458.72

i think maybe i added a result value

1462.4

i came in here and set a couple of uh

1465.919

properties around a few of these fields

1467.76

and then i come in here

1469.039

and it's going to come in and remove

1470.64

field image link which i just did

1473.2

so i can actually see my entire history

1474.799

of changes to my database

1477.039

as well

1480.4

let's see i think let me go back and

1482.24

make sure

1487.279

and then um just for grins we'll go

1490.4

ahead and whoop sorry

1491.52

here i'm gonna run this

1496.48

i can find my run server line real quick

1499.6

there we go i'll close that out

1506.48

oh i'm already running it i'm sorry i'm

1507.919

running it over here

1510.159

and let's just make sure we close it and

1512.64

reload it

1515.6

and from that now i'm going to see now

1518.32

i've got a couple other things here but

1521.279

now my site is up and i want to actually

1523.2

flip over to the admin side

1526

remember because uh this sort of

1529.2

somewhat for free we've got and i'll

1531.919

show that in a minute

1534

um is that because we built this

1537.84

we can actually see the um on the admin

1540.799

side we can see our

1542.64

tables groups and users is in there by

1545.6

default

1546.96

frequencies i can see what the

1548.48

frequencies are that i've entered i can

1550.08

look at

1551.279

ping types i can look at result types

1554.4

i can see some sites that i've already

1555.679

done i can add those so i can do all of

1557.679

this through the admin but we're going

1558.96

to have a front end

1560.159

and as a reminder uh

1563.44

the authentication authorization that's

1565.76

an application that it's it's already

1567.36

built those

1568.24

into this admin side monitor i had to

1571.039

add them

1571.84

and i had to do that through admin dot

1574.559

py

1576.64

and that is one that i'm pretty sure i

1579.44

have to create

1581.039

let me double check that just to be sure

1586.64

uh yes i do have to create by default it

1588.64

does not have an admin dot py

1591.6

but if i want tables to show up here

1595.84

then i need to do this which is um

1599.76

pretty simple i have to import the admin

1601.84

from djangocontrib and that

1603.44

says that i'm hooking you know i'm

1604.72

connecting to the uh the admin

1607.279

app essentially and that's what that

1609.679

admin is

1610.72

and so for each of these uh and i'm

1613.2

going to pull my models

1615.039

since i did it for all of these guys so

1617.44

i'm going to do

1618.32

um lookup frequency ping result insights

1621.44

all four of them

1622.48

and then with each one of those all i'm

1624

going to do is create a

1626.159

class that inherits from the model admin

1628.24

for each of those

1629.6

i get a display a list of columns i'm

1632.64

going to display

1633.44

which is here on the list so i can see

1635.6

name and url

1636.96

for these it's going to be name and code

1638.96

and you can see that name

1640

code name code name code name url

1643.039

if i wanted to add another column um

1646.559

let's see if i think i can look up a

1648.72

result i think there's a field there

1650.96

and i can add that actually let me go

1653.2

look at my model real quick

1655.679

uh oops

1659.44

uh let's see well let's just

1664.32

now let's do less yeah let's do last

1666.84

check

1668.399

so if i do last check over on admin

1675.919

then i'm going to see it's going to do

1677.84

an update

1679.279

which it did

1682.399

and now if i look over here

1686.48

sites gives me the last check field as

1688.399

well

1690.48

so i can play around with that as needed

1692.24

but i can fairly as we've seen before i

1694.159

can pull these things into the admin

1696

and then all i have to do so i create

1697.919

the class

1699.12

that is essentially the admin model

1702.159

form based on this i mean all that

1704.48

behind the scenes

1705.44

django knows what it needs to do and

1707.2

then i just register i just register

1709.039

each of them

1710

and

1713.2

basically just say you know what i want

1715.039

to call it

1716.72

and or what the model is and then what

1718.88

the

1721.039

admin class essentially the form class

1723.919

is

1725.36

so i can pull those guys in and i'm

1728

ready to go so that gives me my database

1731.919

now i'm going to talk a bit about

1735.279

um we did let's see we've sort of gone

1737.84

into the model

1740.24

um i sort of skipped ahead to this a

1742.159

little bit but that's okay

1743.84

uh so just summarizing that a little bit

1748.32

primary table is sites table uh we've

1751.12

that's where

1752

we're going to list our information

1753.919

we've got some lookup tables that are

1755.36

basically just

1756.559

support tables for that main table to

1758.96

give us an easier way to enter data

1761.84

we do need to create a super user and

1764.32

we're going to talk about populating

1765.52

tables

1766

and fixtures next so creating a super

1768

user

1769.039

is uh moderately simple

1772.799

you just say let's see i think i have it

1776.24

specifically otherwise i may have to

1777.679

look it up

1780

because i always forget even though it

1781.6

is rather simple

1783.52

where did i put that

1790.96

i don't have it okay i think it is

1797.279

i think it is just let's do this i think

1800.72

it's just called yeah create super user

1803.76

so what i want to what i have i've

1806.399

already built

1807.44

but let's say i want to go into uh

1809.36

monitor and actually let's do it this

1810.799

way

1811.679

let me go there we go

1815.2

go back over to monitor now right now

1819.2

if i look in my oh i got to keep that

1821.679

running

1823.52

let me look at my users real quick right

1825.12

now i have a user named rob

1827.36

that i created so that's my only user

1830.72

and this user is has a staff status

1835.52

so it's you know basically it's a super

1838.559

user

1839.919

i can it's active and it's staff

1843.84

if i want to create another user so let

1845.919

me create

1847.279

i'm going to create a guest then that's

1849.919

createsuperuser

1851.039

so i've got that all i have to do is

1853.6

just say

1854.88

createsuperuser just ask me what the

1856.799

name is and so i'm going to call it

1858.799

guest i give it a email address

1865.12

give it a password i think it doesn't

1868.96

like

1871.039

super simple ones but let's find out

1872.799

yeah so if it's too kind i try to use

1874.6

password123

1876.96

and i can it'll save you know you can

1878.559

bypass the validation you want to which

1880.559

i'm going to because

1881.76

i don't need to worry about it so now i

1883.6

will be able to look in here

1886.159

if i refresh whoops i got to start my

1888.32

server back up

1891.44

and then refresh and now i can see that

1894.72

i've got guest user

1896.159

um and again i can see that they're

1899.36

active their staff their super user

1901.519

but i'm going to go in and somewhere in

1904.72

here

1905.2

delete

1908.64

and we talked about these uh users and

1910.96

permissions and things like that in the

1912.159

past i'm not going to rehash that too

1913.76

much

1914.48

particularly because it's not going to

1916

matter too much for our application

1920.08

one of the things that we need to do is

1921.84

we're going to need to

1923.519

do uh enter in these lookup values to

1926.32

some waveform or fashion

1928.24

now we've got this uh this interface

1930.64

that allows us to

1931.6

you know fairly easily do so it's user

1934

friendly good user experience

1936.399

but i do want to mention i want to

1938.48

mention something we've done in the past

1940.48

or that we haven't really covered the

1941.6

past which are fixtures

1946.799

and those allow us to along with the

1950

data migrations

1952.24

we can use those to develop on one

1954.88

machine

1955.919

and those remember those migrations are

1958.159

sql scripts

1959.519

so i can go run those same migrations

1962.72

i can run those on another server and

1964.799

update it fairly quickly

1966.64

what migrations don't do is handle data

1970.24

that is where fixtures come in now what

1974

a fixture is is i can take a look at

1977.76

a table uh for example

1980.799

let's do i think results because i don't

1982.48

think i've done that one yet

1984.96

let me go look real quick in my folders

1987.6

where did that go

1990.159

here it is so i did frequencies before

1993.039

so

1995.12

for results instead of me having to

1998.32

update my database and go do this again

2000.72

i can actually do

2001.76

a dump and that's where fixtures come

2005.6

whoops

2006.799

let me do it this way that's where

2007.919

fixtures come in

2010.32

and so what a all i need to do with that

2013.039

and i'll show you what a fixture looks

2014.32

like

2014.799

i'm going to go in and i'm going to do

2016.799

with manage again we're using this

2018.32

python three manage

2020.159

we do a dump data we give it the

2022.48

application name and then we give it

2024.32

the table name so this time i wanted to

2026.48

do lookup result

2030.96

yeah look up result uh you can give it

2034.32

an indentation because

2035.44

it's basically for pretty printing and

2036.88

things like that and then

2039.039

i'm going to put it into the fixtures

2040.72

folder

2042.559

and i'm going to call it results.json

2046.159

because it's going to generate a json

2047.6

file so i'm going to do that for result

2050

and i'm also going to do it i did it

2051.599

already for frequencies but i'm going to

2053.44

do it for

2058.839

pings

2060.48

and then we'll take a look at those

2061.76

because then what i can do

2068.32

okay so i can i've generated these

2071.76

and now that's the i use dump data

2075.839

load data is the reverse of it and all i

2079.2

do with that

2079.919

is i just tell it what fixture i want to

2081.599

use i tell it

2083.04

the app and the table and it's very much

2085.919

a similar kind of command

2087.599

and it'll actually pull that it'll

2089.359

insert that information into the

2090.72

database

2091.76

so i can i'll do that in a second here

2094.399

so let's

2095.599

look at these first so let's look at

2097.68

results

2101.04

if i look at my data i had

2104.8

uh failure value response is alive and

2107.839

simple response i had these four items

2110

when i created the um the fixture

2113.44

then it creates just a nice little json

2115.839

structure for each of those records it

2117.44

tells me what the model is

2118.8

so here's my app and my table what's the

2121.2

primary key

2122.4

what are the fields and the values and

2124.96

then it just does that for each of those

2126.48

so i can also do that for

2127.839

ping i can see where i've got it for my

2130.079

ping values

2131.52

and i can see it for my uh frequencies

2134.079

as well

2134.96

now note that it has the model within so

2138.16

technically i could just

2140.16

combine all of these uh the data from

2142.8

all these tables into one

2144.16

shot and try to pull it in um

2148

but it's easier to keep track of doing

2150.48

it separately so

2152.4

there's some way there are some advanced

2153.76

things you can do if you really if you

2155.68

have to pull like an entire database and

2157.599

want to do that

2158.8

through django as opposed to the

2160.64

databases uh

2162.72

you know bulk load and backup and

2165.28

features like that

2167.839

but for now we'll keep it you know

2170

simple you can do it on a table by table

2171.76

basis

2172.72

and what i can do is and i'll show an

2174.96

example of

2179.68

load data so i'm going to do the

2182

frequencies so if i go into

2184.88

my database and look at frequencies

2190.32

here's my data and i'm just going to get

2192

rid of all of the records in there

2196.16

so i've emptied my table

2199.2

uh it i think it's okay with that

2204.88

i didn't like that for some reason let's

2206.48

see

2213.68

oh i'm sorry because this has got

2215.119

foreign keywords oh because i've already

2216.48

got a record in there so let me get rid

2218.24

of my site

2223.44

come here if i can double click properly

2227.76

there we go

2229.76

my mistake i forgot that i had

2233.04

we had a record there so if i come into

2236.48

frequency now

2239.2

i can take all of those get rid of oh

2243.52

now let's just do it this way i'm gonna

2245.599

come back there we go okay

2248.24

so now i've emptied those out

2251.28

but now if i wanted to come in and load

2253.44

it

2254.32

should look up frequency right right

2260.32

um oh probably have the wrong

2264.48

i think i called it look up oh what did

2266.24

i call the fixture let's go look at that

2267.76

real quick

2269.04

i called the fixture

2273

frequencies.json so

2282.16

and so now it installed four objects

2283.599

from one fixture and if i go back and

2285.68

look at my data

2287.68

i can see where it installed each of

2289.119

those i went ahead and pulled those guys

2290.64

in

2292.24

so i could do that on another database

2293.76

if i wanted to take this application

2295.68

and quickly migrate my entire database

2299.2

including data

2300.56

then i can use those fixtures they are

2303.119

also useful from testing and things like

2304.96

that there's some there's a lot of

2306.24

different uses for it

2308.16

the built-in test system actually makes

2309.839

use of fixtures behind the scenes

2312.56

so this just gives us a good way to move

2314.72

data

2315.599

back and forth

2318.64

so that gives us a way to create our

2320.4

model create our data

2322.079

and back it up you know move it around

2326.56

so that really is that second working

2328.24

session so now let's

2329.839

switch gears into the front end we're

2332.24

going to talk about

2333.119

our screens for our application our

2335.52

pages

2336.88

and they're really we're going to keep

2337.92

this sort of simple we're going to have

2339.68

a home page

2341.359

there's going to be some base

2342.56

navigational stuff

2344.4

uh like a base menu

2347.44

we've got a header and a footer for our

2348.88

pages we're going to talk about we're

2350.32

going to have a style sheet that we use

2351.68

for application we're going to pull some

2353.28

stuff in there

2354.4

and then we're going to have a screen

2355.599

that allows us to add or edit a site

2357.599

uh one other one going to do is we'll be

2359.52

we'll have a

2360.88

which is essentially going to be sort of

2362.48

the home page as well is we're going to

2364

have a list of

2365.599

our existing sites

2369.44

so to do this we're going to create some

2371.599

more files and

2373.119

fill these things out and this is where

2374.24

there's going to be a lot of code i'm

2375.52

going to go through but i'm going to try

2376.64

to

2377.28

walk through it somewhat quickly because

2379.76

it's

2380.64

it is moderately repetitive so hopefully

2383.599

you guys will be able to

2385.76

easily take a look at that when you pull

2387.76

down the code

2388.88

if you want to build your own example

2390.64

then it should be easy to read and

2392.8

modify

2394.56

so we've got a couple of things that are

2398

key i guess to building a page we have

2400.64

to have a url we have to give it an

2402.32

address

2403.2

we have a view which basically says hey

2405.04

when i get to this address

2406.48

this is what i'm going to do we're going

2408.8

to build an html template because we're

2412

it's sort of as a you know jumping the

2413.76

gun a little bit here but when we build

2415.04

out a view at some point we're going to

2416.24

display something which is going to be

2417.68

an html page

2419.359

maybe with a form within it

2422.4

and as part of those html pages we're

2424

going to have a template which is going

2425.76

to be sort of our

2426.88

basically we're going to be storing our

2428.4

header and footer things like that in

2429.839

there

2431.52

and then we're also going to talk about

2433.359

our style sheets so that we can

2435.119

give it a general look and feel

2438.72

let's see so we jump over here so let's

2440.8

start with our urls

2443.44

let's see we can close a couple of these

2446.48

down a little bit simplify a little bit

2451.52

let me close a couple of these off

2459.52

so start with our urls now urls is

2462.48

actually generated

2464.16

um you have some by default

2467.599

so i'm just gonna do a cat monitor two

2471.52

monitor two oops monitor two

2475.359

uh by default there's very little that

2478.88

it gives

2479.52

which is and that little is the admin

2481.599

site if you remember when i did

2482.96

fired up monitor 2 i was immediately

2484.88

able to flip over to the admin site

2487.839

and that's because it's built that slash

2490.24

admin

2491.359

if i do anything else on it then it's

2494.4

it's going to tell me that it can't find

2495.92

it basically

2497.44

and i think we have seen that before you

2499.76

will see

2500.48

an example somewhat like do i have that

2502.48

running in the background

2504.4

i do not let me run my server again and

2506.24

i'll show you an example if so if i come

2508.16

in

2509.44

and give it an address that it doesn't

2511.359

know what to do with it

2512.56

it's going to say hey so um i'll just

2515.44

call it mistakes if i try to go to that

2517.119

page mistake

2518.48

it's going to say page.found and it's

2520.56

going to show me this is what

2522.72

is actually defined within the url so

2524.72

these are the patterns that i register

2526.24

that i

2526.8

recognize now notice

2530.24

i'm seeing this because i have debug

2531.92

equal to true in my settings file if i

2533.92

change that to false i'm not going to

2535.2

see that i'm going to get a standard for

2536.64

a fuller page

2537.92

so while we're working on this while

2540.16

we're developing

2541.52

you know debug on we're going to se or

2543.359

equal to true you're going to get a lot

2545.359

of useful information

2546.72

this one for example i don't know how

2548.48

many times even building this little

2550.56

application

2551.76

where i had a typo or something like

2553.599

that and i could easily

2554.96

say oh here's what i'm looking here's

2556.72

what i sent here's what i

2558.48

you know oh wait this is what i meant to

2560.079

send and so i can correct that

2562.4

and then it'll direct me accordingly

2567.119

now it includes the uh admin

2570.48

and uh by default and that's the only uh

2574.64

and uh import path which is this uh

2578.24

the patterns we're looking to match i'm

2580.88

keeping them very simple you can

2582.24

actually get more complicated with your

2583.839

patterns uh you can do

2585.28

uh regular expressions and things like

2586.96

that but i'm going to keep them simple

2589.52

one of the things i'm going to do is

2590.72

from monitor my application i'm going to

2592.96

import views so it's going to go find

2594.92

views.py

2596.56

which we're going to go fill out here in

2598.24

a little bit

2600

and from the django piece

2603.04

i'm going to import include because that

2606.079

allows me

2606.96

for the uh the user authentication piece

2610.079

that i'm going to use

2610.96

i'm going to go ahead and include in uh

2613.599

accounts

2615.119

and then i'm going to take and i'm going

2616.72

to have so slash account which i could

2619.04

be this could be users could be a lot of

2621.2

different stuff but i'm going to hang

2623.119

off of the accounts url address all of

2626.4

the urls

2627.52

that are the auth related urls which are

2629.76

things like login and log out

2631.52

things of that nature so that's more of

2634.319

a security thing

2635.839

that's built into django so we're going

2637.359

to take advantage of it

2639.28

and then we go to our pages we have our

2641.2

home page which is just going to be

2643.119

our our default now so if we don't give

2644.88

it a if we just go to the

2646.8

site it's going to jump at our to our

2648.48

home page

2649.92

sites which is going to be our ability

2652

that's going to be a list of the sites

2653.28

that we've entered

2654.4

we're going to be able to edit a site by

2656.16

giving it an id

2657.76

we're going to add a site if we don't

2659.2

give it an id and then we're going to go

2661.28

to

2661.599

we're going to have a youtube user

2662.88

registration page

2666.079

and so those are our urls and so now we

2668.4

have home page

2669.68

list sites edit site ad site and user

2671.92

register that we have to build out

2674.56

in our views and so as we flip over to

2678.319

our views

2679.52

um a lot of this stuff is going to come

2683.359

um as we go

2686.64

so there's a couple of these i can

2688.319

actually eliminate out i don't use time

2690.48

zone

2692.319

um but i'm going to leave these in here

2694.079

anyways for right now

2696.56

and this would be stuff that again

2698.24

you'll get the code and you can

2700.24

fairly quickly i think you'll see what

2702.4

you need and what you don't need

2704.4

and like i said chango is pretty

2706.079

friendly so when you try to run

2707.28

something and it doesn't

2708.96

see something it's expecting it will say

2711.119

hey i can't find

2712.72

you know such and such a library which

2714.96

usually will imply that you then need to

2716.48

go

2716.8

and import that library you know or do

2718.48

it from

2720.88

now home let's just sort of walk through

2725.599

our pages from the view point of view

2729.28

um i'm going to come back we'll look at

2732.16

some of these html things here in a

2734

little bit

2735.76

this is the the logic behind it so for

2738.8

home page

2740.079

uh we're going to come in and we're

2741.2

going to see if the user is logged in

2744.079

if they are we're going to go to

2746.119

welcome.html

2747.28

so they're going to get a welcome page

2748.96

otherwise

2750.96

i'm sorry if they're not they're going

2752.72

to go to the welcome page if they're not

2754.24

logged in

2754.8

if they are it's going to go to the list

2757.28

of sites

2759.52

and notice one it's going to render so

2762.319

it's going to

2762.88

actually it's going to say all right i'm

2764

going to kick over and render the html

2765.68

page

2766.24

this one says instead of going to slash

2769.68

you know just slash as your home it's

2772.64

going to redirect me to slash sites

2775.28

which is going to go to the sites page

2777.44

so i'm going to if i start here

2779.76

and i'm logged in it's going to redirect

2781.599

me to sites so it's going to go to this

2783.52

list sites call and that's just behind

2786.8

and just within this it's going to do a

2788.079

quick redirect and now i come into list

2790.64

sites

2791.2

so we take a look at that one which is

2792.72

sort of our it's our home page for

2794.48

people that are logged in

2796.56

um if they are authenticated in this

2799.76

case if they're logged in

2801.119

so if they try to go to the sites page

2802.64

and are logged in

2804.24

then it's going to get all of my site

2806.079

objects or site records out of the

2808.16

database there's no filtering

2810.72

i'm going to set up a parameter of sites

2813.44

which is all that list of

2815.04

all records and then i'm going to render

2816.88

the site list and i'm going to send it

2819.04

parm the parameters which happens to be

2822.4

the list of all sites if i'm not logged

2824.8

in it's going to tell me to go log in

2826.96

and i can see that here

2830.24

i think i am logged in

2833.28

so if i go to sites

2837.52

it takes me to uh my sites if i log out

2840.72

and go to the same thing then it's going

2843.04

to take me to

2844.16

my welcome page and we'll take a look at

2846.8

how these things got built out

2848.48

here in just a minute so that's list

2852

sites

2853.2

another page i'm going to put together

2854.48

and notice i just kept all these secure

2857.04

from the start so if you're not

2858.8

uh let's see if you're not logged in

2861.359

it's going to send you to the login page

2862.64

so all of these

2866.72

um if i try to go to like

2870.839

site then it's going to ask me to log in

2878.8

if i try to go directly to any of those

2880.4

and then i can log in

2882.48

and get it so i've real quickly i mean i

2886.24

didn't have to

2886.8

really build much to this is just this

2888.72

accounts login if you remember that was

2890.48

included from the auth

2892.48

piece here whoop sorry accounts

2896.319

and then i added all of the auth urls so

2898.4

one of them is account slash login

2901.2

and so i go here and i can see that

2902.96

that's my login

2905.359

so once i go for edit site that's going

2908

to take

2908.88

an id this is the only one that's taking

2911.92

a parameter so it's going to be

2913.52

so if i do site slash one and this is a

2916.88

node

2917.2

this is with the slash it's not a query

2919.359

string parameter

2920.64

so for example um if i do site slash one

2925.68

that's going to try to get me something

2927.28

and it does not exist i don't have any

2928.8

sites right now

2930

if i do it as a query parameter that's

2932.48

different so i'm not saying

2934.319

id equals one

2937.52

in that case it's going to

2940.8

think that i didn't send anything so

2942.4

it's going to try to add a site

2944.079

because that's not a that's not a query

2945.52

string parameter that's an actual

2947.2

part of the url that we are addressing

2951.2

here since if i just give it a query

2953.44

string version then it thinks that it's

2955.04

this because it gave me cite plus a

2956.8

query string

2960.96

so edit site if i give it an id it's

2964

going to say it's checks to make sure

2966

if it's not not zero so if it's not a

2969.28

if it's an id that's not zero then it's

2970.72

gonna go try to find the data for that

2972.4

site

2973.28

uh we saw what happens if it doesn't you

2974.96

get a you know four one says hey i can't

2976.88

find that

2977.92

uh otherwise if it's a zero as an id

2980.4

it's going to create a blank record

2984.4

so which basically works identical to ad

2987.119

but we just i did it this way so it's a

2988.88

little more

2989.68

uh ponderous approach if we post to this

2992.88

site

2993.68

so if i'm doing an update and posting

2995.68

then i'm going to grab the data from my

2997.76

form

2998.8

and um i'm going to see if my form is

3002.319

valid and then i'm going to go ahead and

3003.599

save

3004.079

and then i'm going to once i've saved my

3006.079

record i'm going to go back to my list

3007.52

of sites

3008.559

and we'll take a look at this in action

3009.92

a little later here

3013.52

so i come through for edit i will create

3016.4

a

3016.72

blank form which i did here so it's from

3019.92

site form and we'll take a look at those

3022.079

in a minute

3023.68

i'm going to send my id across and then

3025.68

i'm going to have a title for the page

3027.28

that i'm going to use

3028.559

and then this is going to call

3030.839

siteedit.html

3032

for add site it's very similar i still

3035.2

call site edit

3036.8

basically the only difference is i just

3038.559

come in and

3040.079

create a blank form i don't ever

3043.52

do the here where i'm trying to grab

3047.359

an object from the database based on the

3050.72

primary key

3054.64

and so um two other things

3058.4

i went ahead and i've created a logout

3061.68

that i can call

3062.72

and the user registration

3065.839

user registration is so we can actually

3069.359

create a user within our

3070.88

application and that's a form that we'll

3073.44

take a look at we've got a registration

3074.96

form

3075.76

and there's a registration html that's

3077.76

just some additional

3079.359

administrative pieces you really don't

3081.44

need to log out the register

3083.04

or even to check the authentication you

3085.2

could just say i'm just going to let

3087.04

whoever hits this application see

3088.96

everything

3090.559

so i built these

3093.76

and one of the things i want to do now

3095.04

is go for my views is we've

3097.2

referenced these forms all over the

3098.88

place forms

3100.64

are the application version of

3104.16

the model now i've got a couple forms

3107.68

that i'm

3108.4

i'm basically stealing from django which

3112.079

is user creation form

3113.68

in user and those are so i can do the

3116.4

registration

3117.44

and the user login so that gives me a

3120

really easy way to

3121.599

create and administer users those

3125.359

pretty much you're just going to use

3126.319

what you you know what comes you can see

3128

there are

3128.559

certain fields that you can require or

3131.28

not you can make some tweaks to it but

3133.839

that's sort of outside the scope of what

3135.2

i want to cover this time around

3137.599

i do want to look at my primary form is

3139.68

the site form

3141.44

and within that it is based off the site

3144.319

model

3144.72

sites model and i'm going to give it my

3149.359

list of values that are going to be on

3151.76

my form

3153.2

for each of these i'm giving them with

3155.2

labels i'm going to give them sort of

3156.319

some pretty

3157.2

labels for them and we'll see these in a

3159.359

minute

3160.319

and then there's some widgets that i've

3161.599

got here to allow me to do

3164.559

input most are pretty simple i've got

3167.359

text where i'm limiting the size

3170.72

and i'm giving it a class this is a css

3173.28

class in case i wanted to play around

3174.64

with that

3176.24

um and then i've also got a text area so

3179.44

text input

3180.079

single line text area i have uh

3183.92

multiple rows here i've got so i'm going

3185.839

to do two rows of 80.

3188.16

it probably should actually be three

3189.359

rows because i have a 250 limit on that

3191.28

one i think

3192.88

and then um that's pretty much and then

3196.64

a number input so

3199.44

those are my forms and so now

3203.119

i can go to uh let's look at our views

3207.28

let's take a look at the the html side

3209.839

of this

3213.599

um there's two things one

3216.96

first we're going to have a we're going

3218.079

to add a static folder

3220.079

which has to be addressed in settings

3223.2

and that's where we're going to put uh

3225.359

like our javascript our css

3227.68

images things like that so those will

3229.839

all go in our static folder

3231.599

and then by default we get

3236.079

a static url and then

3239.28

and all we have to add is that our

3242.559

um where our static files directory is

3246.8

so i'm calling it static so it's just

3248.88

off of my

3250.24

off my base directory for my application

3253.44

with static this os path join

3256.64

is a operating system

3260

generic approach to adding combining

3263.28

values to give you a path for the

3265.28

uh the hard drive for the you know the

3267.28

local drive

3268.72

so it takes care of things like you know

3271.119

backslashes versus forward slashes and

3273.119

things of that nature

3275.04

and again this is stuff where you not a

3277.119

whole lot you need to do other than just

3278.559

know that it's out there

3279.52

and once you've got it you know once

3280.559

you've googled it you throw it in there

3281.92

and boom

3282.799

you know you're ready to go now within

3285.2

my static

3286.4

i pulled down the bootstrap files i

3288.559

think we've seen this before so i'm not

3290.16

going to

3290.64

go dig that up and this just happens to

3292.799

be because i'm going to use bootstrap

3295.839

i do although i don't need to use this

3298.96

blog guy

3300.24

i'm not actually using him anywhere so

3302.48

i'll just move him to trash

3304.96

within the css uh one of the things that

3307.68

bootstrap gave me is the form helpers

3309.839

javascript monitor css is my application

3313.28

and then i've got these images in case i

3315.44

need them

3317.68

now static comes in use when i go to my

3320.96

templates

3321.839

so templates is where it's going to look

3324.4

for html stuff

3326

so when i go to you i'm sorry a view

3331.119

and i look and i say you know create

3334.119

register.html then it's going to try to

3336.079

look for that within

3338.88

the templates folder and so i have

3342.559

site edit which i've created here

3346.079

and now with each of these so let's

3347.44

start with our welcome

3350.4

uh it extends base.html so this

3354.24

this is built on top of base html which

3357.28

i'm going to look at in a second

3359.2

if you remember we have blocks

3362.319

and so we have this content block that

3365.359

is going to be

3366.16

part of this html before the block

3369.76

that content block it's going to go pull

3372.799

in

3373.92

base html base html is

3377.28

our generic format for a page

3381.68

we're going to load the static files so

3383.68

everything that's within that static

3385.359

folder

3386.079

we load it and then a lot of this

3389.599

is like here static we're going to pull

3392.48

in our bootstrap stuff both the css and

3394.72

the javascript

3397.44

um we've got the form helpers one we've

3399.599

got some jquery javascript that's pulled

3401.44

in for bootstrap

3404

pulls in another little javascript and

3405.68

now we pull in at la one of the last

3407.119

things we do is

3407.92

and all of these are sort of your

3409.68

standard uh link for a style sheet

3412.48

h reference and then i'm gonna give it

3414.48

uh within stat

3415.92

uh within static css

3419.76

monitor gives me whoops and i just

3422

accidentally hit that

3423.92

pulls in my my css i create a header

3427.52

which i'm using

3428.64

this is a pretty standard bootstrap

3432.16

navigation in effect it gives us this

3435.599

little thing here

3436.96

which also is responsive so as i shrink

3441.04

it down it gives me my little

3443.119

hamburger menu so i do that to give me a

3445.359

nice little responsive interface

3450.16

uh let's see i get my i set up my menu

3452.96

items

3453.839

which is just basically a home and then

3455.92

if you're logged in

3457.119

uh i've actually i'm using some it's

3459.2

still pi uh django so i can say if the

3461.28

users log in if they're authenticated

3463.359

then i'm going to allow them to have ad

3464.799

site and login i'm sorry log out

3467.599

if they're not authenticated then

3469.92

they're going to be asked to log in so

3471.44

they just get home and log

3472.48

in so if i log out i just get home and

3475.359

log in

3475.92

if i log in i get home

3479.04

add site and log out

3482.96

and then i have my content block

3488.559

and i'm wrapping that in a div that's

3491.359

going to be of class content

3492.799

i'm going to see that with our style

3493.839

sheets a little bit and then i have at

3495.76

the bottom

3497.119

i have a footer which is going to be of

3498.88

the standard footer class

3500.4

and i've just got some basic text for

3501.92

that at the very end

3504

pull in some additional uh javascript

3507.44

which i think didn't already have that

3508.559

one bootstrap yes i did

3511.44

i pulled in some javascript that i

3512.88

actually pushed that stuff to the bottom

3515.599

just for speed and so it comes in at the

3518.16

end and then

3518.72

finally comes in and pulls in javascript

3520.72

that it needs

3522.4

so that gives me our base so i've got a

3524.559

footer i've got a header

3526.319

and then i've got my content so if i

3528.64

look at welcome

3530.319

there's a header up here uh this content

3533.92

block and then there's going to be a

3535.04

footer underneath it

3536.4

my content block i've just got i've got

3539.76

javascript included here which is very

3542.48

simple

3543.28

for my on clicks so i can log in and

3545.599

register

3546.48

i've got a little text and so

3549.76

i can see that right here uh oh i'm

3551.839

sorry that's actually not it this is the

3553.2

welcome

3554.88

so i can see i've got my login button

3557.839

i've got my

3558.88

register with the site got login

3560.799

registered the site register

3563.52

i did not have one of my templates set

3566.319

up so we're not going to look at that

3567.44

right now

3569.119

oh i'm sorry i can check i can fix that

3571.359

real quick

3573.28

it's not called external it's called

3576.16

base

3577.76

and i think that will give me all i need

3579.52

so now

3580.96

yeah so now i can do user registration

3584.16

so i could add a user if i wanted to uh

3586.72

it gives me some help for each of these

3588.4

what is it

3589.2

you know as far as your username your

3591.2

password

3592.88

and it's a very straightforward uh here

3596.079

let's see so i do

3597.52

if you guys remember uh i bring in the

3599.92

registration

3600.88

form and let's go look over here real

3603.359

quick

3604.4

for user register so i'm using this

3607.92

registration

3608.799

form which i pass in i pass the form

3612.079

as form is the parameter

3616.4

i'm going to pass that into register dot

3619.119

html

3620.559

and so i can come in on the register

3622

side and i can do a form

3623.68

and i can either there's three ways i

3625.52

can do it i can do it as a list

3627.839

as an unordered list as paragraphs or as

3630.64

table

3631.44

if i want to do a table i can change

3633.76

that real quick

3637.92

and it's going to be a series of rows

3642.96

if i do that as a registration now it

3644.88

looks more like a table

3646

i get to the end after the table

3649.76

if you remember i have to send it a csf

3652.52

csrf

3653.76

token because i'm going to be if i'm

3655.359

going to do data entry stuff

3658.88

and then i have my submit button

3662.079

and then i've so i've put this together

3664.079

and i've also got my little helpful text

3666.799

you can also log in if you have an

3668.839

account log

3670.24

in bam bam and so i

3673.44

i built my header which is the

3674.88

navigation i've got my footer

3677.28

which is down here which is also very

3679.04

straightforward

3680.48

and then this is my content now you you

3682.88

may see that i've got my nice little

3684.799

coloring for that that i picked up with

3688.16

my

3688.88

css uh monitor

3694.079

if you remember i used a class content

3697.68

for that main block and so with each of

3700.799

those

3701.28

i've just come in and i set a width

3704.16

which is 90

3705.359

i have it centered basically because

3707.2

it's got a padding to the left

3709.52

of 5 so it just kicks it over five

3712.88

percent

3713.68

i also take the text within it and push

3715.92

that over five percent

3718

and then i've got my background color my

3719.839

forward color and then my height

3721.44

is just eighty percent so it just sort

3723.52

of limits it so it's a nice little small

3725.359

screen very

3726.559

uh you know early 90s look and it's also

3730.4

responsive so doesn't look too bad as it

3733.52

shifts stuff around

3736.88

now uh that is so if i want to add a

3739.76

site

3740.96

so that's my welcome site list is what

3742.72

i'm looking at here this one's a little

3744.4

more complicated

3746.079

um i've got an if here so if the user

3749.119

has a first name then it's going to say

3750.88

sites for that user otherwise it'll say

3753.28

my sites

3756.079

and then i've got my add a site button

3759.039

which just takes me to add site which is

3762.4

right here otherwise i'm going to say if

3765.359

i have

3766.48

let's see so if sites which is if you

3769.119

remember that's a list of the records

3770.64

from the sites table

3773.039

if that has some entries then it's just

3775.52

going to be a force of foresight

3777.039

insights

3777.68

so for each record i'm going to call it

3779.44

site and then

3781.359

i'm going to come in and build out a

3784.64

listing of those which we'll see that in

3786.24

just a second

3787.119

and then i do an end for if i don't have

3789.599

any then it's just going to say no what

3791.119

sites entered which i have here

3792.799

click on add a site to get started

3796.64

and we'll take a look at this second i'm

3798.319

i've got each of these displayed

3800.559

there's going to be a css class site

3803.119

which we're going to look at in just a

3804.24

second so let's create a site

3807.119

and this again oops let's look at that

3808.48

real quick create a site i'm doing a

3810.72

form as table

3812.72

and i use that site form that we use

3815.92

here

3816.319

so i'm going to see site name

3817.76

description test url ping type

3819.68

blah blah blah i'm going to see all that

3821.2

kind of stuff so i'm just going to it's

3823.44

going to display

3824

that out i set the table or the title

3826.48

which is either add or edit

3828.88

and then i've got a save changes and

3831.28

then note

3831.92

i've also got my csrf token so i don't

3834.4

have to worry about

3835.28

cross-site issues so i'm going to add a

3837.92

site

3843.839

i'm going to do it this is the dp

3846.319

homepage

3850.839

heartbeat

3852.24

the ping type and i just had a couple so

3854.88

i'm gonna do a heartbeat

3856.319

uh the test url is https going back

3858.799

slash

3860.68

developpreneur.com

3864.16

desired type is uh going to be is alive

3868.799

desired value don't have to worry about

3870

that because if is alive it's just

3872.559

going to be a response uh and i'm going

3875.359

to do this

3876

every five minutes and so i'm gonna

3878.64

that's my

3879.52

heartbeat check when i do save changes

3882.079

now i could see a list of sites

3886.079

uh which is whoops site list

3889.92

and so here this is where it's going to

3893.2

for each record within there it's going

3896.079

to do

3896.559

an md5 and an md1

3900.48

which we can there we go as it gets

3903.68

smaller the 5 is actually

3905.52

because of the size of the screen it

3906.72

gets funky pretty quick but

3909.119

normally what i'm going to see is if i

3911.44

have multiple rows

3913.52

let me add a second site let's see

3917.039

i'll do my this one real quick

3923.44

i'll do the same thing i'm going to do a

3925.119

heartbeat

3932

calm i'll go straight to that page

3936.559

simple response well it's gonna be is

3938.72

alive

3940.4

don't have to worry about that and do

3941.92

that once an hour

3945.44

save changes so now we can see two sites

3948.839

together

3950.319

each of these i've cleaned these up a

3951.68

little bit and

3953.68

i can either edit or nope i didn't have

3955.839

an on click so if i want to edit one

3957.52

then i can come in and i can edit that

3962.839

page

3966.72

uh from this so let's take a look at

3968.559

from the uh

3970.16

the css point of view uh because that's

3973.68

this is something we wanna we're gonna

3974.799

wanna play around with a little bit i

3976.24

think to make our applications more

3977.76

useful

3978.48

and because of the power that uh django

3980.96

gives us

3982.079

it makes it pretty easy for us to

3985.44

you know clean this stuff up and well we

3988.559

can use css anywhere

3994.96

apologies um

3998.559

so here i'm sorry so we're going to go

3999.76

over our css and we want i wanted to

4002

step into this a little bit just because

4003.599

we haven't spent much time on it

4006.079

so if we look at our what did i call

4008.72

that i call

4009.599

that site

4013.28

so here's my class

4017.599

and i can do quite a bit with this as

4020.319

you can see this is a

4021.76

mother moderately lengthy

4024.799

css entry and i and with this i'm doing

4027.2

things like i'm setting the radius we

4028.799

can see i

4029.28

as i hover i get my little background

4032.88

it has a sort of beveled kind of look

4036.559

and i found the easiest way for us to

4039.359

play around with this stuff

4041.839

is actually through pretty much any of

4043.52

your modern browsers

4045.119

if you want to change a look and feel

4047.359

then you go up here so like

4049.92

here i'm selecting it's hard to see i

4051.599

know this is very small text but

4053.2

i'm selecting this item so i'm going to

4055.44

select

4056.559

a site and then over on the side i'm

4059.119

going to be able to actually see what is

4060.64

the css that's being used

4062.72

and i can start playing with this live

4065.119

so i can change my background color

4066.88

let's say

4067.92

instead of that gray i want it to be uh

4071.76

red yeah that's so that's pretty ugly

4074.48

but

4074.799

you know i could say instead of the

4078.48

text color the one that it was

4082.48

i want to change it to be oh i don't set

4085.28

the color

4087.2

uh but whoops

4093.52

let's see if i can add a color real

4095.28

quick uh shoot i can't because

4102.4

okay there we go there we go so now so

4104.88

if i do color

4106.319

uh white then i can change that

4109.839

um i can also change around my padding

4113.359

so i can go from

4114.88

25 to 30.

4120.239

or i can drop it to nothing and see that

4122.799

now my padding has been moved over

4124.96

i can work with my margins

4128.48

so i've got a bottom margin here i've

4130.08

got a little bit of space

4131.52

i could get rid of that i could start

4133.279

cranking up the

4135.6

uh and within the padding so now i can

4137.6

like really tighten some of this kind of

4139.12

stuff up

4140.48

i could increase the font i

4143.839

could decrease the font uh whoops

4147.199

that's not decreasing the font that's

4148.64

decreasing the font

4151.199

and then the the quick way to play

4152.799

around this stuff is play around with it

4154.64

live

4155.279

and then you can just copy and paste and

4156.88

just take all of that copy it out of

4158.319

there

4158.96

flip over here and i could make that

4163.12

part of my css and boom i'm off and

4165.92

running

4168.48

now that that hits i know we haven't

4171.52

gone too deep into this but that does

4173.199

give us at this

4174

point uh an application

4177.839

that we're entering some stuff i've got

4179.839

some basic css we'll talk about this a

4181.759

little bit more

4182.719

uh in a future session we can enter some

4186.239

data and that leaves us

4188

the next time we come around actually

4190.159

with this with this information to build

4192.319

a back-end that actually is going to do

4194.88

these checks based on pings and things

4197.44

of that nature

4202.719

so what have we covered we went through

4206

the basic app

4207.04

creation uh actually basic project

4209.44

creation

4210.08

and that included creating an

4211.44

application with it we looked at forms

4213.84

we looked at our model

4215.199

views urls went through some nice basic

4217.76

stuff

4218.56

put our application together that way

4220.96

looked at setting up our css and

4222.56

actually including that in

4224.4

and it's again much like any other web

4226.56

application you're using the same kinds

4228.56

of

4229.6

commands it gets down to its javascript

4232.4

and html

4234

i talked a little bit about some

4235.28

troubleshooting kinds of things as far

4236.96

as you know being

4237.679

having debug turned on and being able to

4240.64

play around with that

4242.159

and using our django environment for

4244.88

things like

4245.679

um backing up our data

4248.88

and importing it into others um of

4251.679

course doing our migrations and things

4253.52

of that nature

4256.719

so questions and comments

4263.199

yeah i just uh i wanted to say it's all

4265.6

more reason

4266.4

i'd love to uh see if you see if i could

4269.52

use this um

4270.48

you know django to to monitor one of my

4273.04

apps maybe not

4274

write the code in in python but

4277.199

um uh you know do some monitoring and

4280.32

just uh basic operations what you've

4282.159

shown here

4283.04

uh in django just for how easy it is to

4285.28

set up that's awesome

4287.76

yeah it's definitely there's a as a

4291.28

uh an ancillary application it is

4293.679

actually a really

4294.8

solid solution for that so when you

4298.08

and i know you you've spent a lot of

4299.52

times building you know like utilities

4301.52

and things like that those applications

4303.28

and

4303.52

and uh little executables and that that

4306.719

we have to build

4307.84

or we don't have to but we usually end

4309.84

up building

4310.88

because we want to be more productive

4314.64

because there's things that we find

4315.92

ourselves doing all the time and we want

4317.44

to automate the task or simplify it a

4319.6

task or

4320.96

do it in a way that's somebody that's

4322.32

not us that doesn't have maybe the

4324.64

the deep knowledge of the core

4326.239

application that they can

4328.159

do stuff that they can you know do some

4329.92

administration or do some reviews or

4332.159

reports or things like that

4334.159

and uh the more i play around with the

4336.239

more that i find that both

4337.6

the python itself and because of it's

4340.64

so lightweight and so uh

4343.92

pervasive as far as environments and

4345.76

things like that

4347.04

uh and then django if you want to an

4348.88

interface for it

4350.64

it's a really good pairing for doing

4352.239

those kinds of applications

4354.4

so good point glad that you you're

4357.28

seeing the usage as well

4359.199

other questions and comments

4368.719

if anybody's talking they're on mute

4373.12

otherwise go ahead and move forward

4379.199

so that brings this session uh to a wrap

4382.4

i

4382.8

had hoped to get further into it but

4384.4

just as i started looking at it and some

4386.08

of the things i wanted to cover

4388

this is definitely going to have to be a

4389.28

multi-part session

4391.199

we've done we've got the bulk of it

4392.88

we've got actually a very

4394.56

we have a functional front end i think

4396.48

this would count for like a

4398.239

minimally viable product from the front

4400.08

end point of view

4401.36

uh we'll do a little bit of tweaks to it

4402.96

and then we'll come back and swing

4404.4

around to the back end uh next time

4406

around

4406.96

as always i want to appreciate your time

4408.719

thank you for you know listening in for

4410.4

checking this out for

4412.159

comments and everything else if you have

4414.88

any other questions or anything else

4416.239

that you need to contact us

4418.08

you can always catch us at email info

4420.64

developer dot com

4422.4

you can go out to the contact us form on

4424.36

developernoor.com

4425.76

we have a youtube channel that you can

4428

go if you go

4428.8

look for developpreneur from youtube

4431.199

then you'll find it

4432.08

and you can subscribe and we put stuff

4434

out uh twice a week

4435.52

tuesdays and thursdays right now we've

4438.159

been a pretty steady schedule for the

4439.44

last year so i'll probably maintain

4441.679

vimeo is not um

4445.52

not as frequent as what we've put out

4448.32

from the youtube side

4449.84

we more often will put things like the

4451.679

these mentor classes will show up at

4453.28

vimeo first

4454.56

and then eventually they'll show up on

4456

youtube

4457.6

and then uh if you want to keep us from

4460.48

the podcast point of view you can always

4462

check out the better developers podcast

4463.92

or develop an order podcast

4465.6

it goes by both names for example if you

4467.84

have alexa or something like that say

4469.44

you know alexa enable better building

4471.6

better developers

4473.04

and it'll start playing the latest

4474.64

episode and just

4476.32

some of the ways we have to communicate

4477.92

to you guys and

4479.36

ways for you to communicate back to us

4481.92

as we work together to try to make

4484.08

every developer better so go out

4487.76

have yourself a great day

4498.09

[Music]

4510

you