Building Data-Driven Web Apps with Flask and SQLAlchemy Transcripts
Chapter: Jinja2 templates
Lecture: Create the PyPI site

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Before we can jump into our template example we have to do one thing really quick. We don't have a PyPI demo site yet
0:08 so we're going to actually create that now and then we can add templates and Dynamic HTML to it. So kind of a review from when we talked
0:16 about creating our first site but we haven't actually done this formally for this project. So let's just take two minutes and do that.
0:22 So over here in the Jinja template we're going to create a final thing, we have started from scratch
0:27 so this one has no starter. But when we go over here and we're going to first create our virtual environment.
0:34 See the command that's actually running at the top but just Python 3 create a virtual environment and activate it.
0:40 And then we have this here, just, remember what we did we wanted to have the overall part that manages this thing.
0:48 So we might have like a requirements.txt also had a dev for one of those. We might have setup and readme's and all those kind of things.
0:57 And then we're going to have a pypi_org or then this is going to be our actual web content. And here we'll have things like the static folder.
1:06 The views. Templates, most importantly for this one. We had other stuff, but we're not going to add that yet.
1:14 And let's go ahead and add the here as well. So if we go back we can now open this in PyCharm.
1:22 And the quickest and easiest way to do this on mac OS is to go to the directory that contains the virtual environment
1:28 and dragging and dropping that onto PyCharm. On Windows and on Linux you have to go up here and say file, open, directory.
1:35 But hey we get a little shortcut, that's cool. So here we can see we've got our templates folder that's already kind of detected. We've got our app
1:42 let's go ahead and add our requirement of Flask. Make sure we've detected the virtual environment so let that go as I've actually get to it.
1:51 Here you can see, and we can say which Python. On Windows say where, and you see that's actually the one were looking for. So we can install Flask.
2:00 IP list is empty, install Flask. If we look, all the Flask stuff is here. Okay great. And that's because PyCharm automatically detected
2:13 the requirements file and so on. So we'll import Flask, this is super quick because you've done this before. We'll say app = flask.Flask(__name__)
2:25 like so. And then we'll say @app.route /index return hello world. And here we can just say but lets be little bit better about it, we'll say
2:39 do the main example. So if __name__ == '__main__' and we'll say We're going to add a whole bunch more good stuff to the startup here.
2:48 Little cleanup, let's just run this and make sure that everything runs. Also, let's mark that as a sources route
2:54 so these are all relative to each other. I pressed a bug, didn't mean to but whatever it also works so it says we're running production
3:02 because we're not setting a couple of settings which we can do. Let go and run it. Hello world. Looking good huh? All right.
3:12 So we can mould our app and say, debug=true for now. Of course you want to put that in a configuration. We rerun it.
3:20 You'll see now, the debugger's on which is nice 'cause if we make a change, it automatically detects and reloads this, so.
3:28 All right so we're in good shape, we're not quite done but we're making progress for getting our app up and running.
3:35 Now, we're going to actually start working with data and using these templates to generate Dynamic HTML
3:40 using Jinja 2 and our models and all that good stuff.

Talk Python's Mastodon Michael Kennedy's Mastodon