Mastering PyCharm Transcripts
Chapter: Server-side Python web apps
Lecture: Creating server-side projects

Login or purchase this course to watch this video and the rest of the course contents.
0:02 Let's create some web apps.
0:04 Here is our working demo code and in this web world
0:08 there's so many files and so many ways in which you create these projects
0:12 and certain working directory has to be the top of your project
0:17 and all those kinds of things for this all to work really well.
0:20 So what I'm going to do is I've created some subfolders here
0:23 and we're just going to go into those folders and create a new project in there.
0:27 So we'll go over here and we'll say create a new project
0:31 and then notice, we can pick a bunch of different options
0:35 for the server side frameworks,
0:37 now we can expand those out, so here is Django,
0:40 we could figure out what kind of template language we want,
0:43 what the template folder is going to be,
0:45 name it, enable the admin, all the things you might do.
0:47 Similarly for Flask can get its Flask settings, template folders,
0:50 and whether or not it uses those templates, sadly Chameleon is missing
0:54 Google App Engine, Pyramid we can come over here.
0:59 Chameleon is amazing and definitely should be done there,
1:03 so let's suppose we want to go into this folder and create it here
1:09 and I wish there was a better way to copy a path
1:12 but I don't know maybe there is that I just don't know, but let's copy that.
1:18 So we're going to put this over here
1:22 and we're going to say let's have first_pyramid
1:27 now notice, PyCharm actually updated middle of this class,
1:36 which is awesome, that means you guys get to see a slightly newer version
1:38 but they added one really awesome feature
1:42 which is they have improved how virtual environments are created
1:45 and they give you this ability to create them inside your project.
1:51 I like to name my .env, but venv, we can go with that.
1:55 We can just check new virtual environment, bam, right off,
1:59 I'm going to choose Chameleon
2:02 because Chameleon is a much better language than Jinja 2,
2:06 even though it's less popular, still I think it's way better.
2:09 It's my opinion, I'm happy to talk about why, outside of this class.
2:13 Okay, so let's focus on the web side, so we are going to create this,
2:18 in this folder, it's going to be a subfolder here, it creates a virtual environment,
2:25 now this web framework was not installed in that virtual environment,
2:29 none were, right, because it was brand new
2:32 so it's going to install all the dependencies that we need
2:35 also, like before, because we created this inside course
2:42 which is the git repo, I'll just say add root
2:45 so we get version control, that's awesome.
2:48 Now, there's a couple of things that we have to do for Pyramid to actually work
2:52 and notice, PyCharm is helping us right here.
2:56 One of the things is we've installed the base
3:03 we've installed the base Pyramid,
3:06 but this version, this particular configuration
3:09 runs with things like Pyramid, debug toolbar and Chameleon
3:12 because I checked that box and things like this.
3:16 So it didn't install everything I need to run
3:19 it needed everything to sort of bootstrap Pyramid.
3:21 And how does it know that this is the stuff that's required?
3:25 Well, this is really part of the set up here
3:28 so these things, notice, it's just a random indentation warning,
3:35 but this stuff right here is what's required up there, that's not listed.
3:40 So let's look it in the setup file— I already said that, so that's pretty awesome,
3:43 let's go ahead and hit that, and wait a second...
3:50 Great, that worked.
3:52 Now the other thing we have to do, this is specific to Pyramid
3:56 and it's a little bit funky compared to say Flask,
3:59 but it is not that different I guess then Django in that,
4:03 in order to run this, we have to run some scripts to kind of configure it.
4:07 In Django, we have manage.py,
4:10 over here in Pyramid, this thing is actually a package that's why it has a setup.py
4:14 and then in here is our actual web code, you can see our templates folder.
4:18 So in order for this to really work,
4:20 we're going to need to run setup.py develop
4:24 so we can actually just click this here and it will run that,
4:27 and then everything is ready to go.
4:29 Remember, the red means that these files
4:31 have not been added to source control.
4:33 Okay, so it looks like it might run, let's give it a shot.
4:37 Success!
4:39 Look at that, we have our web app going,
4:42 everything looks good and we even have our little debug toolbar extras
4:45 that got added in with things like our requests,
4:53 with our performance analysis and stuff
4:55 and by the way, 1 millisecond response time,
4:59 our processing time, it's pretty awesome.
5:01 So that's how we get started here, it says
5:03 do you want to register that in source control— yes we do.
5:06 So, we're up and running, we have our views
5:08 let's just write a little bit of code to kind of round this out,
5:10 we're not going to use a request,
5:12 so in Python the way you say there's this input parameter that is required
5:15 but I am not going to use it,
5:17 let's say underscore, so that warning goes away,
5:20 and let's just go over here and change this
5:22 to demo project from PyCharm something like that,
5:29 so we're going to take this, this is mapped to a route which is just /
5:33 and it renders this Chameleon template under templates
5:37 and we're going to pass something, a value for project over there
5:41 so let's go look, notice we've got a templates folder and a shared layout
5:45 which is the general look and feel of the site
5:48 and then specific details for each page
5:50 and down here, where are you—
5:53 oh, for some reason this hardcodes this, that's not right.
5:56 So, this should have project here, so it's using that,
6:00 let's try this again— ah, so this is really important for the web,
6:05 see this, we have an error, and it looks like we've done something wrong
6:08 but it says the address is in use, and notice it's still running over here
6:11 but with Python you've got to restart the web app
6:14 to pick up changes in the code,
6:17 like here, but not for the templates.
6:20 So, how do we do all this?
6:23 First, we could press that button, but let's just stop these and make them go away
6:26 and we go back here, and we go to edit configuration
6:29 and you can check single instance only,
6:32 that way if it's running and you rerun it, it'll just automatically restart,
6:35 so if we rerun it, it's running, and if I try to run it again,
6:38 it will say we're going to restart that,
6:40 and I just say yeah, always do that.
6:42 So this is definitely the way to do it for the web
6:45 and now we have our demo project, this is being passed,
6:47 there is a little glitch in the template thing that came out, no big deal;
6:51 very nice, we have our Pyramid app up and running.