Placeholder Image

字幕表 動画を再生する

  • Hey, and welcome to the tri Django Siri's.

  • My goal for this one is to help you learn and Master Django like I want you to go as far as you possibly want to go.

  • And understanding the jangle Web framework you see in the way we're gonna do this in this one is really Start from the beginning, we're gonna start with absolute basics and then we're gonna work our way up introducing new concepts along the way.

  • And I'm actually not gonna be building a full project.

  • So instead, what I'm gonna do is just jump into individual concepts, put them into a practical use case in a sort of project, and then eventually you'll have a very good understanding of how to build riel Web applications using Django.

  • And of course, I do recommend that you learn from entire projects and I have a bunch of them both right here on YouTube, on joints.

  • If he dot com slash YouTube as well as on our website joints heavy dot com, we have a tonic stuff there from building riel things with Django.

  • But this series is all about getting the absolute basics to even advanced level things bit by bit.

  • If you're learning Django for the first time, it's an incredibly exciting experience.

  • At least it was for me because once I was able to actually build a Web application with a database attached to it, it was like, Oh, this is so cool.

  • Now I think that you might be just as excited.

  • And perhaps you've already done that with other Web applications.

  • Or perhaps this is the first time your programming.

  • Either way, the most frustrating part is at the beginning, not so much because of the programming language, but often because of how to actually set up your system.

  • And since it's so frustrating over years, we were find the way to set up your system, depending on what you're on.

  • And that's part of the frustration is like you're gonna see me working a lot in a Mac so Mac OS environment, and if you're on Windows, you're like, Hey, why isn't it the same?

  • I mean, actually, using python and actually using Django is the same on both systems.

  • Because Python is python and Django is jangle.

  • The commands to get there might differ slightly, but realistically it's the same over years we've refined the installation process, and all of that could be found on joint safety dot com slash from zero.

  • So if you just do that step one that set up process, you'll be ready for the rest of the Siri's.

  • You don't have to go on to any other step other than setting up your system before you jump there.

  • I did want to mention one other thing, and that is the code.

  • So we have all of our code on get hub or joints.

  • If he dot com slash get hub to shortcut it, you're gonna look for the tri Django depository.

  • So So join TV Dotcom Such get help will take you here.

  • And then if you go into repositories, you'll see all kinds of them.

  • And in fact, if you type out, try Django.

  • You'll see multiple there as well.

  • I want you to ignore all of the ones that have numbers in them and just go to the one try Django, right?

  • So there's a link right here if you want to go directly there, but this code will 100% help you because when you hit roadblocks, which gonna want to do is take the code that you've been writing and take a look at Get Hub and make sure that what you've been writing is the same as what we've been doing in the videos.

  • That part is critical.

  • And then the last thing is, when in doubt, consult the documentation.

  • Jangles documentation is very well written, and there's just so much there that you can learn that we won't necessarily cover because they give additional context.

  • Or they give specifics to whatever use case you have for the technology.

  • And then the last thing is, Google is your friend.

  • You know you can use Google to do a search for something that you're not familiar with, and oftentimes that will bring up stack overflow dot com.

  • Stack Overflow has all of these questions from people for all sorts of programming languages, including python, including Django, including JavaScript, all sorts of things in there, and you just do a quick search.

  • You can search for just jango, and you can learn a lot just from that just from going toe like votes.

  • I mean, does Django scale?

  • That's an interesting question to take a look at, and then what is know what is blank.

  • I mean, this right here is a great learning resource as well.

  • So what I'm gonna assume for the next video and all the other future videos is that you have your system set up and ready to work with Django and Python.

  • The versions that we're gonna be using will be discussed in the next one because they will change over time.

  • At the end of the day, I really want you to stick with whatever version is in the video, because as a beginner, that is critical.

  • All right.

  • So in this one, we're gonna be creating a brand new virtual environment and install Django.

  • If you haven't done these things before, regardless of the version, definitely stop now and make sure you go back and do the setup process.

  • No, I absolutely want you to have a fresh virtual environment and a fresh Django install, not on Lee, just to get the practice of it, but also to make sure that we're all starting from the exact same spot.

  • So if you open up your terminal window or if you're on windows, your power shell or command prompt.

  • But hopefully you're using power shelf on Windows limits and Mac users.

  • Justa terminal is fine, So if we type out Python V and Python three Dash V, this is what I get now.

  • You might already have Python three in there.

  • So if you see Python 3.6 point five or 3.6 point six right here, you're in good shape.

  • If you see this, then you're gonna have to do an extra step, okay?

  • Just keep that in mind.

  • I believe that open.

  • And I'm just gonna put it over to the side a little bit and break it down so we can just keep that in mind while we're doing this.

  • Okay, so I've got another terminal window open now.

  • You absolutely don't have to do this, but I'm gonna leave it there just in case.

  • So there's a few different ways on how we can create a virtual environment and installed Django.

  • I'm gonna show you the way that I'm going to do it so initially, gonna serve you the final way.

  • And if that part works for you, great.

  • You can go to the next portion which would be installing Django, which maybe we should just do all of that and at first, so I'm gonna show you exactly how I'm gonna do it.

  • Now, I first of all, want to keep this virtual environment in one development area.

  • So for me, when I open it up and a list everything out, this is what I see.

  • Yours might be a little different.

  • Years might be the same.

  • You might see this dead folder if you don't see it just to make their dev right.

  • So, in my case, already have it there.

  • So I get this error.

  • I'm gonna just CD into my dad folder.

  • Right.

  • This is where I keep all of my development projects.

  • So in here, I'm gonna go ahead and make a directory called Trying Django.

  • We're a CD into that directory, and then we're gonna create are virtually envy.

  • Now, before it created, I'm just gonna hit virtually envy and make sure I don't see any errors.

  • I see that there's all sorts of options I could do if I type out ABC, there is an air.

  • So if you see an error, that means you need to install your virtual environment all over again.

  • Okay, so I cleared everything out.

  • But if I do pwd?

  • I see exactly where I am.

  • I'm inside of that folder.

  • If I list everything out, there's nothing in there.

  • Now all I'm gonna do is virtually envy.

  • Dash P.

  • Python three Enter again.

  • Remember how I said if you had Python Dash V and Python three was here, you could just omit this portion right here.

  • Right?

  • So if you see Python 3.6 right there, you can admit that portion and just leave it as virtually envy period we had enter.

  • That creates a virtual environment inside of this directory so I can activate it with source been slashed, activate and then install Django.

  • So Pip installed Jango and my version of Django is going to be 2.0 point seven.

  • So Django equals equals 2.0 point seven.

  • That should also be your version of jingle.

  • If you're sticking with me on this, use that version of jingle.

  • I honestly don't care if 2.8 was 2.0 point eight is out used to 0.0 point seven.

  • We'll upgrade things later.

  • And if you stick with me on this, you will absolutely upgrade with us.

  • I promise.

  • Absolutely Promise Okay, so you hit.

  • Enter, and I'm gonna let that run.

  • Now.

  • For those of you on windows, you're activate.

  • You might remember, is different.

  • It's just slightly different.

  • Well, that installs.

  • I'm gonna just go ahead and break it down a little bit.

  • I'm gonna open up another terminal window and simulate reactivating this virtual environment.

  • So list everything out my CD into death, and then I see the into try Django.

  • I'm back into that virtual environment so I could do source.

  • Baines slash Activate in a mac environment, the window's environment, of course, it's scripts us activate.

  • And then you can also run.

  • Deactivate.

  • Okay, so deactivate just ends the virtual environment.

  • Cool.

  • So what is the purpose of having a virtual environment if you don't already know?

  • It is a simple is doing.

  • Pip.

  • Freeze.

  • You see all this stuff?

  • I see.

  • Django 1.10 point four.

  • If I activate it, sore spending, activate and dupe it.

  • Freeze.

  • All I see is Django 2.0 point seven and P Y T c.

  • That's it.

  • So it keeps these requirements separate.

  • And when it comes to Python and its projects like Django, you want him absolutely.

  • Make sure that that is done.

  • Okay, so we have everything installed.

  • If if this part was done, you're ready to go.

  • You could move on to the next one if you had some issues, or you want to see other ways of starting a virtual environment Stick with me.

  • So notice that obviously, we had all this stuff installed, all that's working.

  • So going forward, just just watch.

  • Just for illustration purposes.

  • You know, I'm assuming that up to this point, if you have it working, then you're done.

  • If you don't have it working, watch this next part rewind and then install the things you need to install because I'm going to go pretty fast, but still explain what's going on.

  • Okay, so I'm gonna close out all of my terminal windows and act like I'm starting from zero.

  • Okay, so I jump in to my terminal window I go into I'm gonna go ahead and make a new debt folder called Deaf to a CD into Deaf, too.

  • And list everything out.

  • Nothing's in there so much.

  • I'm gonna show you three different ways and creating a virtual environment.

  • The 1st 1 is just type out virtually envy and then the name that you want to give it so v e N v.

  • That is a way to do it now.

  • This is irregardless of the Python version.

  • It's gonna go off of whatever the system's default version is, so I typed it out.

  • In my case, it's version 2.7, but that is a way to start a virtual environment.

  • Now, if I want to start it based off of a specific version of Python, I would do virtually N v V and V Dash P python for free.

  • Also, it's called V and B to this gives me a version of python and this python three.

  • So that assumes that if I type out python three, it actually gives me a python three.

  • But if you type out Python three and that doesn't work, this won't work.

  • So what happens then?

  • Well, I can just do which python three or, in other words, find the location where Python three is installed, right?

  • So which Python three will not work if Python three doesn't work right, so every once in a while that you installed python in your system and it's just installed somewhere else and this command itself doesn't work.

  • But wherever that is actually installed on any system and you do something like this, you actually paste in the path to that and hit Enter.

  • That should actually open up Python 34 U.

  • S.

  • So then that means that the final way to actually start a virtual environment is virtually n v v E N v three p.

  • And then the path to that python three I hit enter, and then we'll actually start that virtual environment as well.

  • Now, one other thing I will mention is we can also just make the directory that we want to call it.

  • So I want to make a virtual environment and a brand new directory.

  • This is it.

  • I go ahead and enter a CD into it, and then I could do virtually envy and then period instead of the name and then whatever version of Python I may want, right?

  • So the order of these things doesn't matter that much how I'm running those commands in comparison to what I was doing before, But that's a few different ways on how you can create a virtual environment Now, In my case, I'm actually gonna go ahead and give rid of that deaf to folder.

  • I I really don't need it.

  • But it was all about illustration purposes for getting all of this stuff going.

  • Okay, so, uh, I'll see the back into my original project and just go ahead and leave it at that.

  • Now, if any of this was confusing and you're lost, rewatched the video and do this multiple times because having a basic understanding of starting a new project installing it, you're gonna probably do this fairly often.

  • If you're only here to learn some of the basics of Django and you don't plan on making very many projects with with Django, you may be won't need to do it this way.

  • Now, one more note I will say is perhaps you're like a I don't care about a virtual environment I don't care about doing.

  • All these things will do that at your own risk, right.

  • So you're gonna run into issues if you don't use a virtual environment.

  • And yes, I am not using Kanda Anacondas, a package that's Maur for, like, data science related things.

  • Jango can use a lot of those same packages in my experience.

  • Anaconda and Django don't work that well.

  • But realistically, if you're using Anaconda, you're probably already familiar with that system, and you're probably not going to use virtual environments.

  • However, I will say for this entire series, I would recommend they use a virtual environment just to get used to it, just to get used to how Web developers often use the development environment for Django.

  • Now it's time to create a Django project.

  • See, I've got my brand new clean terminal window open because I want to get in the habit of knowing how to reactivate a virtual environment.

  • So I come in here and a CD into my death folder, where I'm holding everything I see d into my try Jingle folder, where my virtual environment route is.

  • Anna Just run?

  • Well, no, I don't run that virtually envy.

  • Commanding more.

  • We go ahead and Ron Source been such activate, right?

  • So that's linens and Mac users for you.

  • Windows users.

  • It's just scripts slash activity.

  • So if you are in here, you can go ahead and do pit freeze, and you'll likely see this version of Django.

  • That's the version we're using.

  • That's the version I recommend that you use as well.

  • So I'm gonna just leave that open right over here so we can always see it, right?

  • Just a nice little reminder.

  • Hey, that's the version of Django I'm gonna be using.

  • All right, now, let's go ahead and do that all over again.

  • It's really easy, right?

  • This this Hopefully, this is really, really easy.

  • If it's not really easy, I'm going too fast.

  • Maybe you just put it on a slower speed.

  • I know I talk really fast, but I try to get it so beginners can keep up.

  • But also so advanced users like more advanced Web developers that are just learning Django.

  • So all of you can get something out of this.

  • That's really the goal.

  • It's It's a little bit ambitious to achieve, but anyways, okay, So now we're in this virtual environment, and I have this command Django dish admin.

  • So, Django Dish and men is a command that will allow us to do all sorts of things with Django.

  • But the main one is creating our jingle project.

  • So Django Dash and men creates projects and whatever our project name is going to be now, you could do this right off the bat inside of that virtual environment.

  • But what I like to do is create an S R C folder, as in the source folder off the project.

  • And then I go in there, right?

  • So if I go back into my virtual environment, I see that it We have these things in here, right?

  • So I've got the four the four things related to the virtual environment, and then I have my SRC folder.

  • So I changed into that SRC folder and just do Django Dash and Men start project and then my project name.

  • What am I gonna call it?

  • Well, to be original.

  • I'm gonna call it Try Django.

  • That's the name of my virtual environment as well.

  • I realize that.

  • But that's okay.

  • You can name your virtual environment and your jingle project the same because the virtual environment is only for your system.

  • The project yourself will be other places, right?

  • So, like, you'll be on Kid hub and there won't be anything related to our virtual environment.

  • So I'm a start this project.

  • Try Django, and I'll just put a period at the end because I am in that SRC folder I hit Enter and analyst things out.

  • I see managed a pie and my try Django configuration folder that has the name off.

  • You know, try Django because that's the name of the Django configuration.

  • And if I run Python managed up here, why start or excuse me?

  • Run server What I should see.

  • Is it saying something like this?

  • Yes.

  • It's giving me some warnings.

  • We don't Don't worry about that yet, but it is giving me a web address that I could go to.

  • So if I open up my web browser and go there Hey, congratulations.

  • You have Jingle working now if you're not familiar with Jingle 2.0, and this is new to you.

  • This is a new landing page that they've created.

  • It looks a lot cleaner.

  • I like it much better than the old one for sure.

  • So we now have jingle working.

  • It's ready to go.

  • So it's all sorts of things that we can do with it.

  • But before actually jump in to Django itself.

  • What I want to do is start working with some sort of text editor somewhere that I can write the code that is not necessarily inside of the terminal because that gets super tedious for especially for beginners.

  • It gets very, very tedious to write code inside of the terminal.

  • So we're gonna do something different.

  • The next one will talk about that.

  • So stay with us and this one we're gonna download a code text editor.

  • So writing our code is just a lot more user friendly than just typing all of the commands into the terminal or power shell.

  • Right, So we're gonna be using sublime text, but another one a another popular one is called pi charmer P Y charm.

  • So sublime text is 100% free to download and use.

  • If you really like it, you can just go ahead and buy it.

  • I am not affiliated to either one of these.

  • I just know that they're both very popular choices to write out your code.

  • And that's all you're really doing here is you're just writing out your code in these things.

  • They do have some features to make them even more user friendly.

  • But I'm not really gonna go into that right now.

  • All I'm gonna say is, just go ahead and download this and get it up and running.

  • Once you do, just open it up and you'll see something like this, right?

  • So you can have your window open, Make make your sidebar open and you'll see some blank page just like this.

  • So all we really needed you is at our project into it.

  • So to do that, you just go into Project add folder to project, and then we want to navigate tow wherever our project is.

  • Now.

  • In my case, I goto the hard drive users, my user, the dead folder Because that's where the terminal opens by default is right in here and then try Django, I'm gonna go ahead and open.

  • This brings in all sorts of things in here, right?

  • It brings in virtual environment related stuff on also brings in my SRC folder, which has my managed up high and all sorts of Django related things.

  • Right.

  • So this is one of those advantages of using a text editor.

  • It just makes it really clean and easy to see what's going on with any given code.

  • And it also gives you these numbers.

  • Are these lines of code right?

  • So I can say, Hey, look at line 10 and you already can go.

  • Boom Line 10.

  • Okay, cool.

  • So that's another aspect of using a code editor.

  • I mean, there's so many things to it that I'm just not gonna go into now because I could spend probably an hour just going over the set of process of sublime text.

  • Maybe not that long, but anyway, so we now have this folder in here, and we're pretty much ready to use this project.

  • But what I want to do is just save the project inside of sublime text in here and just save it as try, Django, This workspace thing, that's an extra piece on our testing.

  • So don't worry about that.

  • I save it in here.

  • I've got my sublime project.

  • Of course, if you close out sublime text and you are in your project itself and you have something like this like your hey, I'm navigating through back to where it waas.

  • You know, you could just double click on this and hopefully will open up sublime.

  • If it doesn't, then just, you know, do the thing that you need to do, which is get info and just say, make sure that you have open with you know sublime text on there.

  • If you're on Windows, that's right Click and doing the same sort of thing where you just want to make sure that it opens up.

  • But the nice thing is, then it just cuts to right where all of my coat is, and I can open up all the different files that I need and make edits and changes to them.

  • Sublime checks is really cool.

  • Really like them.

  • I wish the response of these videos they don't but I really like the product.

  • So go check it out and download it because we're gonna be using a lot.

  • It's not required, but it is highly recommended.

  • See in the next one.

  • Let's talk about settings dot pie.

  • This is absolutely a basic thing that you'll end abusing a lot.

  • It has a lot of implications for your project altogether, so we'll just go sort of line by line as to what's going on here.

  • Of course, you could read more on the docks because there is MME.

  • Or that is going on behind the scenes than just what will mention first and foremost.

  • We, of course, import the OS because Django works on any given operating system Windows, Mac and Lennox.

  • All of you guys see the exact same thing If you've done what we've done to this point, so you see, we import Os and then we have this variable named based dir that's set to this long string of what the heck is going on?

  • All this does is gives us the path off where Managed up high is but more specifically, the folder that is holding managed up high, which in our case, is SRC So it's that folder right there.

  • Okay, so how I know this is Well, I know python Well, I know jingle well, but how you could figure out where that directory is, that's this right here.

  • So baster just gives you, in my case, that right, so your user might be different.

  • And if you're on Windows, it's gonna be different for sure that the slashes will be in a different direction.

  • So the nice thing here is we know that Django knows where it iss in the system.

  • That's that's important, right?

  • So we can do things relative to Django inside the entire project.

  • That's pretty cool.

  • And this baster shows us that right at the beginning.

  • Um, and you know, you could print out what the baster is, too.

  • If you were so inclined, you can print that out and just run the server again.

  • Let's go ahead and run that server again.

  • And what do you know?

  • It actually prints out that directory for us, right?

  • Just like I said, that's where it is.

  • That's what it is.

  • Cool.

  • Next thing is the secret key.

  • Every jingle project has a secret key that's associated to it.

  • They're always unique to that project.

  • Or at least they should be unique to that project.

  • Um, and you don't want to make it, you know, public in production, because it it could possibly lead to security leaks.

  • And you don't want that.

  • So just doing a couple of changes is good.

  • Okay, next thing is the bug.

  • This is something that's very useful while you're learning, or while you're developing both things when you bring it into a live server alive production environment.

  • It's a real website with real people, real strangers using it.

  • You turn that false, and that has some indications later allowed hosts like domain names that are allowed not gonna get into that right now installed APS.

  • This is a cornerstone of Django.

  • Um, installed amps.

  • There's a bunch of them installed by default, which will go over later.

  • But this is where you're gonna build your abs.

  • Like, you know, if you have a blonde that you're creating, you would put it in installed APS.

  • If you have products, a list of products they have, you would put installed APS, that is, I mean, very core to Django and think of AP s'more in terms of components than apse.

  • Right?

  • So, like APS has taken on a new meaning like your mobile phone has a bunch of APS.

  • It's not like that.

  • It's more of, like little pieces of the Greater Django project itself.

  • Middleware, this is I mean, there's a lot of things going on here, but it has to do with your requests and how requests are handled and also how securities handled and stuff like that.

  • There's something will go over later.

  • It's definitely Maur oven advanced topic, but it's nice because it allows us to know that there's a lot of security features built in, as we can see with some of the ones that are already there route.

  • You're Elle Com.

  • This is something will definitely cover for sure to.

  • This is how Django knows how to route any given your l you know, So, like, my server is running right now, So if I take a look at that running server, if I go to slash you know, whatever this is you're else like So those things are automatically routed by default by Django.

  • Something that's really cool is a built in feature in there.

  • The next thing is templates.

  • Uh, you know, like Jingo renders out html templates.

  • We're gonna go over this a lot, but basically, like where to restore them.

  • How are they rendered?

  • How do they work?

  • All that stuff?

  • We go over later, but it's essentially the HTML page, then gets rendered in Django.

  • It's really cool.

  • It's very useful.

  • And it's definitely a common topic that will go over.

  • The next thing is the W S G.

  • I application.

  • This is how your server works.

  • So the server goes through and uses this setting that's here.

  • In some cases, you change it.

  • Another case says you just leave it.

  • As is next thing databases.

  • General maps to databases.

  • Really really well.

  • So my scale postcards SQL and a few others as well, very easily maps to it.

  • You just change your back end here where it's located and some of the other settings.

  • You can go on the docks to see all of that, but by default, it has a secret, like three database already there.

  • As you might see right there, that's pretty cool.

  • Next thing is we have password validators.

  • This just validates that passwords are good.

  • Oh, or at least good to the current standards of what Jane Doe was found.

  • We have some internationalization stuff.

  • Must skip that for now and then.

  • Finally, static files like Where do you store your image?

  • Is your Java script on your CSS like, where do you store those things?

  • Static files or something will absolutely talk about as well.

  • But but Settings is kind of controlling.

  • All this right's pretty fundamental to how all of our jingle project is running, and that's in our main configuration.

  • I mean, that's it.

  • That's it for setting.

  • So I mean, we will talk and use these things a lot, Maur.

  • But what I did want to mention is one last thing one actual practical thing is is that the database thing?

  • So we had this error here and to run our database, we can run Python managed a p Y migrate.

  • So what this does is it actually sinks our settings, Whatever settings we have with our jangle project, and whatever APS we have, we're gonna go over this again, for sure.

  • But all this is is this right here?

  • So we've got d B.

  • That's egalite three.

  • I just said, Hey, database, make sure you and Daniel are cooked up and you're ready to start working.

  • So if I actually changed this d b two, I could run my great again.

  • And what do you know?

  • Django actually creates a brand new database for me.

  • Now, this is pretty much only true with sequel light.

  • If you had my swell or postcards, Sulu would have to create those databases themselves.

  • But for us, we can just do whatever it like.

  • As far as the database is concerned, I'm gonna go with the default of d B, Don't see light three.

  • Go and delete that file.

  • Now we have a better understanding of how settings work.

  • Let's go ahead and create our first AP seeing the next one.

  • Now it's time to talk about one of the key components of Django, and that is APS.

  • You should think of amps as components or pieces of the bigger jangle project.

  • So the little bits and pieces that can hold a good amount of code, But they're not, like acts like on your mobile phone, right?

  • So if you jump in to the code itself, we see that we already have some amps installed by default.

  • Right?

  • So this is also where you'd put third party APS as well as your own, right?

  • Um, that's pretty cool.

  • So let's take a look at the default or built in ones that we can look at.

  • The very 1st 1 is called admin.

  • And if I go into my project and type out admin, I'll see something like this, this jango administration.

  • So I already have a user name and password, Phil, then because I used jingle all the time.

  • But you probably won't see anything in here yet, you know, And actually, the question should be is like, how do I actually get in here?

  • Well, I'm gonna go ahead and jump to my terminal.

  • Notice that I have two terminals windows open.

  • I have one that's running the server.

  • And then one that's just in the root of the Jingle project, also known as Fort Managed.

  • A pious.

  • You can see how I got there.

  • Right there.

  • So there's a couple things that definitely need to happen.

  • First of all, I want to make sure that I wouldn't run Python managed up here.

  • Why?

  • My great, I see something like this, right?

  • I have a few APS on there that are built in.

  • Those were there by default.

  • Um, I don't want to see errors here eventually, but you definitely want Make sure that migrate is done because we want to create our first user.

  • And then is python managed up here?

  • Why create super user?

  • That one command will allow us to create a user that has access to the admin.

  • This is not a regular user.

  • This is just the ultimate super user, right?

  • So the user that ulin abusing in my case, I'm gonna use the user name of CF ae gonna leave a the email address empty, and then I'm gonna type in my password now the password typing doesn't actually show up.

  • And also, when you're developing, when you're testing in your learning, you can use whatever passer do you want here.

  • It doesn't have to be that secure.

  • It has to be secure when you go live.

  • When you build a real project, that's when you really want to be secure.

  • So I've got my user name here, and my password in my cases just learned code all lower case and I can actually log in to this admin.

  • Okay, So what I did here was actually created user that's actually in the database.

  • Jenko did all that stuff for me.

  • I didn't have to do anything really cool.

  • So that makes things super easy, super user friendly.

  • And that same action would happen regardless of the database.

  • Pretty cool.

  • So we actually just talked about the first portion or 1st 2 portions of built in components or built in installed apse.

  • Right?

  • That's off in admin.

  • Off is that user right?

  • So I actually created that user.

  • I created a super user, and then admin is what I just logged into, right?

  • So I can click on users and I could see Maur about this off user.

  • I can come in here and say Justin Mitchell, right and hello at team Cioffi dot com.

  • And what do you know?

  • That is my user now?

  • I could save it.

  • I can do all sorts of things in here inside of the admin.

  • We'll talk more about the admin in the future, but it's really cool.

  • I can also delete users.

  • I can go back and create new ones.

  • You know, there's a lot of built in things about the M in that really nice.

  • But this is all about the apse, right?

  • The next few things.

  • Well, they're not relevant to us just yet.

  • So what we want to talk about is actually creating our own custom maps.

  • So we've done some of the basics.

  • Now let's do a custom map of our own and have it inside of the admin.

  • When I say custom app, I mean our own data.

  • It's our own structure of data.

  • Let's see what that looks like in the next one.

  • And that last one.

  • We saw some of the built in features of Jang Go's project, right.

  • We saw some of these components, also known as APS, that allowed us to have a user and an admit.

  • Those two things are phenomenal.

  • They're really easy to use and very user friendly.

  • But what we want to do, and the purpose of using Django is to build our own APS, our own components.

  • Now let's not confuse APs with, like, What's on your mobile phone?

  • It's much more about just little pieces of this greater whole that is your Web application.

  • So let's go ahead and jump into the root of your general project.

  • I'm gonna use that term a lot.

  • The roots of the Jingle Project is referring to manage up high.

  • So where Managed Up High is assuming that you have your virtual environment activated and that's where you want to be?

  • Whenever I say roots of the jangle project, I'm gonna assume that that's the case.

  • So I'm navigated there and, of course, this is where it's actually located on.

  • My system might be a little different for you.

  • If you don't want to get there, just go back a few videos in this Siri's It's linked below.

  • Make sure that you watched some of the basic stuff there.

  • Anyways, let's go ahead and create our own custom app.

  • So Magoo Python ends up here, Why start app?

  • And then whatever one want to name the app now I'm gonna go ahead and name it products.

  • And you could do the same thing by pressing up and renaming it to blogged.

  • Or you could do it Two profiles or you could do it.

  • Thio cart, Right, So I can name it all sorts of things, right?

  • And honestly, those four names actually fit with, like, an e commerce project, right?

  • And if we look back into the code itself, you see that?

  • Hey, I've now have all of this new code inside of the name of those different APs that I just created.

  • Now, this does show us something that we could work towards, like we get totally build an entire project that does all of these things.

  • But also what it should illustrate to you is that each one of these abs should do one thing and one thing really well.

  • Like the products AP should really just do product related things, not cart related things that should be separate.

  • That should be in its own cart app.

  • Ah, and we'll get to what that means later But the idea here is that your app should be pretty narrow and focus once it starts to get wide.

  • That's when you start to bring it into another app.

  • And as you see, it's really, really easy to create nap.

  • So there's really no reason to not do it other than perhaps laziness.

  • And I want to avoid that in the long run for you.

  • That's why I'm telling you about it now.

  • Okay.

  • So I want to show you how to use a nap in the way of storing data.

  • Okay.

  • The abs are really good for storing data and mapping.

  • What data you wanna store to your database.

  • So that means I'm gonna go ahead and delete some of these other acts that I just created because we just simply don't need them.

  • Um, because we're still learning.

  • Right?

  • So I delayed it, deleted these other ones, and now I only have products.

  • So opening up models up.

  • I will talk about the other files later, but for now, just models up high.

  • I want to store a product, right.

  • So I want my back end to have memory off a product that I created.

  • How do I do that?

  • Well, I write a class called Product, and in this class, I wanted to have various attributes to it.

  • Right.

  • So I want to say that it has a title.

  • I want to say that it has a description and, you know, perhaps that's it for now.

  • Maybe I just want titled the Scripture.

  • Maybe I won't price too.

  • Okay, so that's a title description and Price.

  • Now, I want these mapped to the database.

  • So how do you actually do that?

  • Well, in Django, it's actually fairly straightforward.

  • We use something called model Fields so models dot we just type out miles dot It's already imported by default.

  • And I'm gonna just use text field for each one of these.

  • For now, we'll talk about more advanced fields later, but let's just use text field on each one, okay?

  • And then my product itself, the actual class that I'm using here I needed to inherit from the default Django class of model.

  • Okay, so this means that it's gonna get a lot of features that we absolutely need to make this work that we just won't go into just yet.

  • That's getting more advanced.

  • But here is a very, very simple model called Product.

  • This will map through the database, and we'll see that in just a moment.

  • So since I created model Stop, I and I created this app.

  • I need to add the app in the settings installed APS.

  • And that's really simple.

  • I just put my own here and just write out products.

  • The name of the app that I created.

  • Right?

  • So that's the folder here.

  • So I've got products I haven't sold amps.

  • We're gonna go ahead and put a comma after it.

  • And now what do I do?

  • I, of course, make sure that I save my setting.

  • Stop I and models up high.

  • And now what?

  • I can run.

  • Is this thing called make migration?

  • So python managed up.

  • He Why make migrations and then Python man shop?

  • He Why migrate?

  • Okay, so those commands you're definitely going along.

  • Remember soap I thought managed up.

  • He Why make migrations And then python managed up here.

  • Why migrate?

  • Okay, So the first time I did it, it made some changes.

  • The second time I did it, it didn't do anything right.

  • So I want to run these in conjunction with each other every single time I change models that pot.

  • So let's go ahead and add in another field here, and I'm just gonna say active.

  • Okay, Let's just do summary instead of description.

  • Right?

  • So we got a description and summary those two might go hand in hand.

  • But now I've made a change to the model.

  • I saved it.

  • And now I want to run make migrations again.

  • It's gonna ask me for basically a default, and I'm just gonna go ahead and say two for now.

  • We'll get into that later.

  • But I'm gonna go ahead and say default and say, This is cool, Exclamation mark.

  • Okay, so I run make migrations again.

  • And then I wore on my great again.

  • Now, why the heck did I show you all that?

  • Well, the main reason is to remember that we always run, run, make migrations and my great When we make changes to models up high, any time, any place anywhere, that is super super important.

  • Cool.

  • So we've got this model now, and I want to take a look at this model inside of the admin.

  • So all I do here is going to end up high and do from dot models import product.

  • So this is a what's called a relative import.

  • It's importing the product class from the models DuPuy and its relative because, and mend a pie and mulls up high or on the same, you know, directory.

  • They're in the same module, so I could actually do that Relative import.

  • And all I do here is an men dot site register and product.

  • We say that and with our server's still running, I go back into my project, my own Django admin.

  • I now see this new thing here called products, and I can add a new product, new description, some price and the summary.

  • Hey, I've got my default in there and saying, This is cool.

  • This is awesome.

  • An exclamation mark had saved, and there we go.

  • We've now created a new product and it saved in the database.

  • And that's the That's really the core and the basics of it.

  • All right, there a basic model saved in the database.

  • Now I could use this over and over again to save all kinds of data in the database.

  • This is not a great model.

  • I will say that like This is pretty limited in scope on how it is.

  • We'll get into more advanced features of that later.

  • But for now, that's pretty cool.

  • That's all we have to do for a model.

  • That's it.

  • So we still need to do is see how to do this in the python shell that is actually just using python commands to save some stuff.

  • Now what we want to do is just used the python shell to create new products, so I used the admin before.

  • Now we want to use the python shell.

  • So to do this, I want to make sure that I'm in the root of my genial project.

  • You know, we're managed, a pie is, and I'm Iran.

  • Python matters up How p y shell.

  • So when you do managed a P Y shell, that means that all of the jangle projects stuff will work inside of a python interpreter so it enter.

  • It looks like a normal Python interpreter, but it's not because I can do from products.

  • The models import product, right so I can do these kinds of imports like an import classes, just like we sort of did in the admiral, right?

  • I did a relative important.

  • The admin.

  • This is closer to an absolute import inside of the show.

  • So I go ahead and enter here and I can do product that objects that all this is a built in jingle command.

  • We'll get over this sometime in the future, but for now, if I enter, I seeing that there's only one thing in here, right?

  • There's only one item, and that's because I only saved one in the video.

  • That's all I did.

  • You might have done it otherwise.

  • You might see a lot more there, and that's cool.

  • If you have, that means that you're experimenting.

  • That's awesome.

  • But for me, what I want to see is Maura.

  • I want to actually create them right here in the shell.

  • I wanna have the ability to do those commands.

  • So it's simple.

  • We just do product of objects that create.

  • And then we want to create new ones inside of this command itself.

  • Inside of create itself again.

  • This is built into Django.

  • This is default by Jingo Standards front.

  • So in models, we look at the things that are required for this product.

  • We have four fields that are required so I can pass those four fields in here as title new products to write and description as another one right price being, you know, whatever price.

  • And then finally, summary being sweet.

  • Okay, notice each one.

  • Each argument in here is a string itself.

  • Right?

  • So I did that on purpose.

  • They're all strings on dhe.

  • That's how I can create a new product ahead.

  • Enter it creates it.

  • I could press up and enter again.

  • It's creating new A new products, right?

  • And if I did that product dot objects that all again, what I see here is a list also known as query set again.

  • We'll get into that later, but it shows us all of those new products created now, assuming we still have our server running, which I do, you can close it out with control.

  • See?

  • But if I just go ahead and make sure that my servers running, I can come back into my admin.

  • Right.

  • So you log in here.

  • I mean, you see this, you gonna products?

  • What do you know?

  • I've got all those products in there.

  • So that's another way to actually create things in your database.

  • Just by using the command instead of clicking through and going to the form and doing all that pretty pretty awesome.

  • So we still have a lot more to do.

  • Obviously we want to see this in another form.

  • But before I jump into another form, I want to see, actually, how Doe I realistically create a model that isn't so convoluted.

  • Like I shouldn't actually pass a string for price.

  • It should be and the actual decimal.

  • Right.

  • And perhaps the title shouldn't be this long text area.

  • Maybe it should just be one short field.

  • So there's definitely things that I need to change to this product model to make it better.

  • That something will do in the next one by adding new fields.

  • So now what I'm gonna do is actually start over on these models.

  • I really don't like what I did here.

  • So in order for me to start over, I can delete all the files in the Migrations folder and just leave in it in there.

  • That's fine.

  • Also, delete pie cash if you have it there and then also, I'm gonna delete my secret, my database.

  • Okay.

  • So back into my models, I want to change these fields for something different.

  • What I just did was something you'll do often while you're learning right, you'll delete those migrations and then you'll delete that database.

  • Sure, you might lose some data, but that's no big deal.

Hey, and welcome to the tri Django Siri's.

字幕と単語

ワンタップで英和辞典検索 単語をクリックすると、意味が表示されます

B1 中級

Python Django Webフレームワーク - 初心者のためのフルコース (Python Django Web Framework - Full Course for Beginners)

  • 10 0
    林宜悉 に公開 2021 年 01 月 14 日
動画の中の単語