Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Preview
Start a free Courses trial
to watch this video
We're almost there! Let's wrap things up and discuss some ideas of how you can expand this project further.
This video doesn't have any notes.
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
All right,
let's write these last two functions.
0:00
They're gonna be very similar, they're
basically just mirrors of each other.
0:03
And so again I'm going to do
these up here near the top,
0:06
just because they're not
involved in a lot of the stuff.
0:09
So flask_template_prepare
will take a string, and
0:13
we're gonna just do a bunch
of transforms to the string.
0:17
So we're gonna do re.sub.
0:20
And we're going to escape any opening
braces and any percent signs.
0:23
And then we're going to replace that
with a less than and a percent sign.
0:33
We're gonna do that for all of string.
0:38
And then I can actually copy this and
I'm gonna do, I need four.
0:42
Three, four.
0:46
Okay, on the second one here,
we're gonna reverse this and
0:48
we're gonna do a percent sign and
then a closing curly brace.
0:53
And that would go to a percent sign and
a greater than symbol.
0:59
And then here we're gonna do two of those,
which would go to two of these.
1:04
And here we'll go to two of those,
which would go to two of these.
1:10
So we're basically just swapping
each of these things around.
1:15
So now for, and
we need to return the string.
1:19
So now for flask_template_repair,
1:26
we wanna do basically the same work but
wanna do this in reverse, right?
1:31
So let's actually just copy this.
1:34
This might be a little faster.
1:37
It might not be too.
1:39
I'm not sure.
1:40
So here, let's just say that
we're gonna take and turn that
1:42
into that.
1:47
And we actually shouldn't need to root.
1:51
We might need to escape these.
1:55
We shouldn't need to
escape these over here.
1:56
So here we're going to do that and
that goes to that and that.
2:00
That and that goes
2:04
to that and that.
2:09
And finally greater than, greater than
goes to close close on curly braces.
2:14
So yeah.
2:21
So less 10% goes to {%,
greater than goes to %} less than and
2:24
less than goes to {{ and
greater than greater than goes to {{ and
2:29
greater than greater than goes to }} and
return the string.
2:35
So for both of these it's just
a bunch of reg x substitutions,
2:40
nothing ridiculously crazy.
2:46
We're just taking brace percent combos,
turning them into chevron percent combos.
2:48
Double braces and two double chevrons, and
2:53
then we undo those things
by swapping them back out.
2:55
We're already using them in
our create_files function,
2:58
but we're not using create_files yet.
3:01
So we should create_files and
we can do that right here.
3:03
We can do create_files and
we wanna pass in the project_root,
3:07
the project_slug, and the project_name.
3:11
Now, assuming everything is done
correctly, we should be able to use this.
3:16
So let's go ahead and test it out.
3:20
So python3 builder.py,
I want to do this in
3:23
users/Kenneth/Projects/files_systems/de-
mo/.
3:28
I wanna call this Demo Project, I'm
gonna do this with a space in name now.
3:35
Says it created it,
let's go over here and look.
3:39
We have demo, we have demo project,
we certainly have thing.
3:42
I'm wanna look at this
in here a little easier.
3:47
So that's demo_project,
so let's look at app.py.
3:50
Yeah, that looks like our app.py.
3:54
We have the index.html and everything.
3:56
Cool, requirements has
everything in there.
3:58
Let's look at the index template.
4:02
We can see that we have our
demoproject.css, demoproject.js and
4:05
we have the correct curly braces and
everything, so that's nice.
4:08
And if we were to look in say,
4:13
static css, demo_project.css,
we have the demo project project.
4:15
Great, there's all of our stuff.
4:20
If we wanted to, we could install Flask
and we could run our app right now, and
4:22
it would all work.
4:26
I'm sure you've seen places, and
4:28
I know I pointed a few, where this
project could be improved and expanded.
4:30
You can add a licensed feature,
so people can pick MIT, GPL,
4:33
BSD, or whatever license they wanted.
4:36
You can ask for their legal name, and
4:39
put it in the copyright notice, with their
name and the date into each of the files.
4:40
You can create a placeholder readme file,
for
4:44
the user to fill out with
information about their project.
4:46
I'm sure there are many other improvements
you all will come up with that I haven't
4:48
mentioned or even thought of.
4:51
If you do, share it in the community and
let me know.
4:52
Thanks for learning about using Python
to control your file system with me.
4:55
I know this is an area that I personally
hadn't explored too much until recently,
4:58
but it's a really useful part
of Python and very powerful.
5:02
Python gives me more and
more reasons to use it every day.
5:05
I'll see you all next time.
5:07
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up