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


Talk Python's Mastodon Michael Kennedy's Mastodon