Building Data-Driven Web Apps with Flask and SQLAlchemy Transcripts
Chapter: Your first Flask site
Lecture: Demo: Creating the starter project PyCharm
Login or
purchase this course
to watch this video and the rest of the course contents.
0:00
So you saw all the steps on how to create a Flask app on the command line, and it took, I don't know something like three minutes, or whatever.
0:08
Let's see what we can do with Pycharm. So we're going to go and choose Pycharm this time. The latest edition is 2019.1. We're going to say new
0:19
and we could do pure Python, but we're going to pick Flask. Right we're going to put somewhere I'll say megasite that's com/mega
0:29
its kind of the way we did it before. So you'll notice it will just automatically create a new virtual environment for us based on Python 3
0:35
with a similar name and we've also picked some more settings like Jinja2 as opposed to Mako or whatever and then the templates folder.
0:43
So all this, we just check those off, we hit go. See, create a virtual environment. It's installing Flask. Its written the app.py, almost the same
0:56
you want to be the same, change that to index and up here we've got our structure. Now this is just the structure inside of that working directory
1:05
so I'm not a super big fan of the way that it focus' it but this is what Pycharm does, so off we go and I guess, just to be fair
1:11
we're going to go and create a few new directories like viewmodels, up here hit command n and we can have views. Here, I think we've got that
1:23
and the other one would be to have a requirements.txt and here we have Flask. I'll have a requirement-dev, didn't do this before
1:35
but we'll put -r requirement and let's just say pytest for now. That's not actually something we're going to be using at the moment but there it is.
1:46
So here's our app, it's ready to go. Its created all the structure and everything we need to do
1:51
and we had to add on that little bit of extra structure. I guess we still need to do the js and the css and so on here. Here we go, now we're good.
2:04
Now if we want to run it, we just click this little go button and boom, off it goes. And we click here. Hello world! Again, what a theme.
2:13
So down here you can see its done a little bit more it set some environment variables the Flask app is app.py and the environment is development
2:21
and debugging seems to be off right now. So we can go and configure those but right now its using environment variables and a run configuration.
2:29
There's a couple ways to do that. We're going to see another way that we can do that in code as well. So here you can see we have our development mode
2:36
we can check off debug if we want to have it running debug mode here we go, we have debuggers active. Super, that means if we make changes, like here
2:47
and save them, its going to detect that and auto reload. All right so that's how you get started in Pycharm. You basically fill out that new Flask app
2:55
and go and you get basically the same structure. Of course, if you want to mix and match that's what I do actually, you can go
3:02
do all the work on the command line interface and then open up the project in Pycharm and continue to work from there.
3:07
So that's probably what we'll do for the rest of the course. I'll just go over this Pycharm style. I think this really helps a lot when you're new.
3:14
As you get more experienced with it you want to tweak things just a little bit and it'll be a little more comfortable
3:19
to use the command line interface. I remember when I was new, I really appreciated all the help that Pycharm gave me, like it did here.
3:25
As I got better, and got more experienced I kind of wanted to go my own way just a little bit so moved over towards the command line side of things.
3:34
Anyway, here you go. Here's how you do it in Pycharm. Remember, this actually takes Pycharm Pro. There's a free Community Edition.
3:41
One of the big omissions from that to help encourage you to pay for it, I guess is the whole side of the web world.