Running the Development Server
All right guys, so in this video I'm going to show you how to create your very first app and what the heck an app even is. But before we do that, we just need to make sure that we have our server up and running. And by the way, if you are using PyCharm, then all you have to do is click this button in the top right, and that's going to kick it off. But for everyone else, then again, just go ahead and navigate to that directory and from here just write python or sudo python if you guys are using Linux or Mac, and then just write manage.py runserver.
And it says there you go. So refresh this and this page should work. And by the way, if you ever want to stop your server, then just go ahead and hold Control+C, and whenever you refresh it, then you can see that it is stopped. But let's go ahead and clear and boot this up again. And all right, so refresh it and it's working.
And by the way, just like a regular web server, you always want this running. And a cool thing about Django is whenever you're working with your source code and you know, adding new apps and like websites and web pages and stuff like that, you don't have to reboot your server every time. You can just leave this running and refresh your page, and you're going to see your changes. So it's like one of the coolest things ever.
Keeping the Server Running
So actually, what I'm going to do is I'm going to take this and just move it off on the other screen, so I don't even worry about it. So what you need to do whenever we need to use the command line again is we just need to open up another one. So I'm going to open up a brand new one, a separate one, and again, this is your server, so just go ahead and keep it running in the background somewhere.
Explaining Django Apps
So let me just go ahead and... desktop, website, clear. All right, so I'll make sure I have that as needed. All right, so what the heck were we supposed to be learning in this video? How to create our very first app.
Now, before I even explain what the heck an app is in Django, I need to go on a little rant, and that is I hate how every single possible thing is called an app right now in software development. You know what an app is? It's those things on your mobile devices, those Androids and your tablets and your iPhone. Those are apps. Photoshop is not an app, Skype is not an app, those are just computer programs. And I know, oh, those are desktop apps. Guys, quit calling things apps, especially everything, Jesus. And whenever anyone makes a website now, they're like, "Do you want to check out my web app?" I'm like, "Dude, that's a website. You don't need to call it a web app, that's a website."
All right, so I say that because in Django, there's these things called apps in it, and they're actually pretty important. So I need to, you know, okay, I just need to calm down a bit. So that's what I'm going to be showing you guys how to do in this video. Basically, your website in Django is going to be composed of all of these little parts, and every single part is called an app. Now, I'll give you guys a quick example. So again, like I said, an app is just part of your website. So on my website, my website isn't made using Django, but I'll just, you know, I'll give you guys a quick overview. If this was made using Django, then this popular section, this would be an app. The forum, the forum would be another app. The video player section, this would be another app. So again, any like main part of your website, that is called an app.
The Single Responsibility Principle for Apps
So again, in Django you have a website, your main project, and it's composed of all these little apps. Now, it's actually pretty cool how Django works with apps because they help you organize all the different parts of your website. And every bit of code is contained, and they all work together really cool. And the rule that you have to remember is each app should do one thing.
So whenever you're developing these apps, if you can't explain what it does in one sentence, then you need to break it up more. So if anyone asks me, what is thenewboston.com? I'll say, all right, it's a website you can go to and it has like a social network and it's a forum and it's also like a video... all right, that's too many sentences already. So I know that I have to break it up in apps. So, what is the forum? Oh, you can go and ask questions. All right, simple enough, that can be an app. What is this part? Oh, you can go and watch all my tutorials. All right, so that can be an app too. So again, remember you have a website, it's broken up into individual different parts called apps. If you can't explain what an app does in one sentence without people getting confused, then you need to take the app and break it up further.
Brainstorming an App-Based Project
Now another random thing I want to talk to you guys about before we get started is this: way back when, I actually had a pretty cool idea for a program. And I'll give you guys a little, you know, summary of what it was. Basically, everyone in the world, like you could set up your own personal web server. And once you had it set up, you could upload all your songs and all your movie files, and it would have a really cool interface. And that way, you can like download from anywhere in the world and also anyone else in the world, such as your friends, they could do the same.
Now this is where it gets interesting. If you and one of your friends were connected, or I'm doing the little quote things with my fingers, friends with one another, then what you could do is you could browse their library and download their songs to your server. So it would be all these separate servers working peer-to-peer instead of a centralized website. And of course, once you connected, they could view your server and download your movies, and I just think it would be really cool. And what would make it even cooler if it was open source. And again, like I said, these would be public web servers, so you can connect to it from anywhere in the world from any device, whether it's your desktop, your laptop, your mobile phone, it doesn't matter.
And again, like I said, since it wouldn't be one central website, it would be server peer-to-peer architecture, it would be almost impossible to shut down. Now again, I'm not talking about like pirating, I'm talking about using these for your personal songs, maybe you play the guitar, or your personal home videos or something like what I do, like I make tutorials, if I want to share them with the world, then it would be a pretty cool idea. Now, of course, this would probably take a lot of work and I'm way too lazy to actually make something like this. But if we wanted to, then how would we do that? Well, with Django, we need to think about it. So each of the different parts would need to be an app. So that means you would probably want like the music files to be a separate app. Maybe you wanted the videos to be a separate app, and maybe you had like a profile section so they knew, so whenever someone tried connecting to your server, they could be like, "Oh, there's your profile photo, his name is Bucky Roberts, that's who owns this server." So each of those different sections would be their own app. So that would be an example.
Creating Your First App with startapp
So if we wanted to make something like that in our program, then what we would do is this. So go ahead and open up PowerShell and again, make sure you're in your root directory. So if you write ls, you should get this. Again, this .idea file, that's just for PyCharm, so make sure that you can see manage.py, and that's it. So how do we make one of these apps? Well, it's easy. Type python manage.py—again, this is a tool that came with it that I said never edit, we already used it before, so again, it's kind of like a multi-purpose tool, pretty awesome—and write startapp. So after this, you just give your app a name. So say that we wanted to develop that music section first so we can upload our, you know, music files, our MP3s, whatever. So I'm just going to go ahead and name it music and hit Enter.
So if we take a look back in our project, we can see that we now have another directory. So this should be right next to your main website directory, and if we expand this, we can see that it came with a bunch of files.