PyCharm With Django5:05 with Kenneth Love
One of PyCharm's best features is its integration with Django. Let's explore how these two great tastes work together.
So I've downloaded my learning site from Django Basics, and 0:00 I want to use that as a project in PyCharm. 0:04 Now I could create a new project, but 0:06 sometimes that doesn't always work out when I drag those files over. 0:07 So I'm gonna choose Open instead, and then I have to find it. 0:11 So it's on Desktop > learning_site, and I say OK. 0:15 And PyCharm was pretty cool, it goes and inspects the software, and it's like, 0:19 hey, I think I see a data base in there so lets let pie charm do that. 0:23 So you say click here, you might see a thing down here about needing to 0:28 install SQL Lite but that's up to you. 0:32 You can give this a name if you want. 0:37 It doesn't really need one. 0:39 And you can hit Test Connection just to make sure it can connect. 0:41 And it can. 0:44 So you say OK. 0:46 And then that's cool, now it has a database. 0:46 So let's look at this database. 0:50 If I look at Django default here, here's all my tables. 0:51 If I look at like step, here's all the fields on step. 0:55 And if I double-click step, then I get to see all of the items that are in there and 0:57 I could, of course, add new rows if I wanted or delete a row or whatever. 1:01 The database browser is really cool. 1:06 This is like one of my favorite things. 1:08 So it sees that learning site as Django project, but it can't run it, 1:11 because we don't have Django installed. 1:16 So let's go see about doing that. 1:18 We're gonna go to Preferences. 1:19 And we wanna look at the Project Preferences, and 1:21 we have Project Interpreter. 1:23 Now, I don't want 2.7.0, I want a new one. 1:25 And I want it to be a virtualenv. 1:28 So, I'm gonna hit these ellipses, and I'm gonna choose creat virtualenv. 1:31 And I'm gonna call it, Learning Site. 1:34 So, there's all of our stuff and we're gonna say OK. 1:38 It's going to create the virtual nv, and nothing is installed yet, 1:42 but we're going to hit OK, just so it sets up for the project. 1:45 And then we are going to back into our settings, and 1:50 here's where we can install packages, which is kind of cool. 1:54 So we're going to hit this little plus sign down here to install a package. 1:56 The package I wanna install is Django. 2:00 Now Django's currently about to get ready for a release of 1.9. 2:02 But I don't wanna use 1.9, I wanna use 1.8, because I wanna be sure and 2:07 use the same one I used in the tutorial. 2:11 So I'm gonna click specify a version, and 2:13 then I'm gonna change the version over here to 1.8.7. 2:16 I think when we made the project is was 1.8.4, but it doesn't really matter, and 2:19 then I"m gonna hit, install package. 2:23 You'll see here it says installing. 2:25 We have a little spinny thing. 2:28 And then it says package Django was installed successfully. 2:29 So we'll close that and then we'll click OK. 2:33 So now, once it reloads everything, it should see that learning site is okay. 2:38 But it doesn't what to run. 2:44 So let's go check that out. 2:47 If we go to tools, we'll actually see this thing here that says run manage.pi task. 2:48 So we're gonna click that, and it fetches our Django commands and 2:54 then gives us a little fake terminal down here. 2:59 An we can run like make migrations. 3:03 What's cool is that it has auto-complete for that, too. 3:07 But what I want to do right now is, I want to do is run server. 3:09 So, not run FCGI, I want to do run server. 3:11 And I just press Return and it's running. 3:15 And if I click this button, then I get a new window, which has my project in it. 3:18 So, there's 127, and there it is, so that's cool. 3:23 So it's running and I can actually just put this down at the bottom. 3:27 And you see here it has this manage.pi, this is the tab that has it in there. 3:30 So if I click that again, I can hit the stop button, 3:34 I can use all these tools in order to control that. 3:37 If I hit the stop button, then it stops running it, and 3:39 I can type in a new management plan. 3:42 So one thing that's really handy in PyCharm, 3:46 is I need to be able to jump to classes quickly. 3:50 So I want to command o, and this helps me find a class name. 3:53 So I'm going to chose Step, which is one of our classes. 3:56 And you can see here we have three classes that have the name of Step in them, 4:00 StepInline, StepModelTests, and the one I want which is Step. 4:03 So I press return and it takes me straight to that. 4:06 Now, if I have something else though where it's not a class. 4:09 I want to just be able to jump to it quickly though, I can hit double Shift, so 4:12 Shift Shift, and then I can start typing in the thing I want to find. 4:16 So maybe I wanna find my function, hello world. 4:22 So it's down here at the bottom. 4:25 I can hit command option zero, or I can do shift shift and go find it pretty quickly. 4:26 So I go there and it takes me straight to that function. 4:32 So those are both really handy ways of getting around in Django. 4:35 There is some other nice stuff in Django where like it kinda knows 4:38 what your text fields and things are. 4:41 And you can also, sometimes, have it insert things for you. 4:44 Where, you know, you can be like alright, I want you to insert something. 4:49 Like property getters or something. 4:57 Most of the time this is more useful for standard Python stuff and 4:59 than it is for Django stuff. 5:02
You need to sign up for Treehouse in order to download course files.Sign up