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