Running the Server4:03 with Kenneth Love
Django has a built-in server that we can use during development.
python manage.py runserver 0.0.0.0:8000 will run the server for Workspaces. On your own computer, you probably don't need the
python manage.py migrate will apply all pending migrations from all apps. More on apps later.
What are migrations?
Migrations are a way of moving a database from one design, a specific set of tables and columns, to a new one. Migrations are reversible, too. The fact that they can be done backwards and forwards is what gives them their name.
[MUSIC] 0:00 >> Okay, so you have Django installed, and you've created a project. 0:05 You're well on your way to becoming a Djangonaut. 0:08 Yeah, that's the collective noun for people that use Django. 0:10 Okay, enough about silly nouns, let's go see how to get Django server up and 0:13 running so we can get to the fun part of building an app. 0:16 So, remember the manage.py file? 0:19 The one that I said would be our main control script, our entry point for 0:21 our project? 0:26 Well, we're going to use it. 0:27 If you did the Flask courses, you'll remember that we had to tell Flask 0:29 to listen for requests on 0.0.0 in port 8000. 0:32 Well we have to do that with Django too. 0:36 If you didn't take the Flask courses we have to do this so 0:38 that Django can talk through our work spaces server to the actual internet so 0:41 that we can see it from wherever we are are on the internet. 0:46 Let's go ahead and run this. 0:50 So what we're gonna do is we're gonna do, first we gotta get in there. 0:51 cd learning_site/. 0:53 I'm in the same directory as manage.py. 0:56 So, I'm gonna do python manage.py and then I'm gonna do run server. 1:00 And the address I'm gonna go to is 0.0.0.0:8000. 1:06 And I hit Return, and you're gonna see a bunch of stuff run through here. 1:14 Don't worry about this too much right now, we'll get back to it in a minute. 1:18 And then I'm gonna come up here to the Preview icon, and I'm gonna click 8000. 1:21 Check that out. 1:25 I've got a Django powered page telling me everything is good. 1:27 That's awesome, wonderful, glad to have that. 1:32 So let's go back. 1:35 And if we look here in our output we have this, you have unapplied migrations. 1:37 What is that? 1:42 What is that about? 1:43 That's really weird. 1:44 So, what this is, is Django comes with some migrations. 1:45 So migrations are a way of moving your database from one design to another. 1:52 You're moving, you're changing the structure, the organization or 1:57 the data in the database from one configuration to another. 2:00 Often you'll find that your table now needs a new column 2:05 to handle an extra little bit of data. 2:08 Or maybe you want to store a preferred name alongside the legal name that you've 2:10 already collected. 2:13 You'd add this column with a migration. 2:14 Which moves the table from one design into the other. 2:17 You can reverse this process too, and remove the column. 2:20 Since you're moving back and forth, that's what gives it the name migration. 2:23 So, we're gonna kill our server here. 2:28 I can do that with Ctrl+C. 2:30 And we're gonna run our migrations. 2:33 So. 2:36 We do python manage.py migrate. 2:37 Just like it says to do right here. 2:40 We follow the instructions that run server gives us. 2:43 It prints out a whole bunch of stuff. 2:46 And we can see that it found a few different operations and 2:48 it's running migrations for I think four different apps. 2:53 So, migrations, I said, were about the database. 2:57 We didn't set up a database. 3:00 Well, Django comes with one. 3:02 So, let's refresh. 3:05 And if we look here, then we have this db.sqlite3. 3:08 Django automatically creates this database for 3:12 us if we don't tell it something else to do. 3:14 So we have this automatically. 3:17 Now this is SQLite. 3:18 This is fine for testing your idea or playing around in. 3:19 If you get really serious, you're gonna wanna move to a real database, 3:24 you're wanna move to MySQL or Postgres, and 3:26 you definitely wanna use one of those two, or one of the other wonderful databases 3:29 that are out there before you go live on the internet and have users. 3:33 Let's try doing our run server again. 3:39 Push Up a couple of times. 3:42 And this time we don't get any error messages. 3:43 And if we come over here and 3:46 refresh our site, it still loads just like it's supposed to. 3:47 If you didn't quite get what migrations are about, don't worry. 3:52 We're gonna be creating and running more of them later on. 3:55 But, the first thing you have to do with any new technology is make your own 3:57 Hello World. 4:01 So, let's do that next. 4:02
You need to sign up for Treehouse in order to download course files.Sign up