Python Flask Tutorial: Full-Featured Web App Part 11 - Blueprints and Configuration

preview_player
Показать описание
In this Python Flask Tutorial, we will be learning how to restructure our application to use blueprints. Blueprints allow us to split up our application into more manageable sections. We will also move our configuration into its own file and create a configuration class. Lastly, we will move the creation of our application into its own function. This is called an Application Factory, and it allows us to easily create multiple instances of our app with different configurations. Let's get started...

The code for this series can be found at:

Environment Variables (Windows):

Environment Variables (Mac and Linux):

✅ Support My Channel Through Patreon:

✅ Become a Channel Member:

✅ One-Time Contribution Through PayPal:

✅ Cryptocurrency Donations:
Bitcoin Wallet - 3MPH8oY2EAgbLVy7RBMinwcBntggi7qeG3
Ethereum Wallet - 0x151649418616068fB46C3598083817101d3bCD33
Litecoin Wallet - MPvEBY5fxGkmPQgocfJbxP6EmTo5UUXMot

✅ Corey's Public Amazon Wishlist

✅ Equipment I Use and Books I Recommend:

▶️ You Can Find Me On:

#Python #Flask
Рекомендации по теме
Комментарии
Автор

I'm glad how these tutorial series first showed us how to create the app without using blueprints, and later, showed us how to utilize blueprints. I've seen some other tutorials where they started out with blueprints and adopted a complicated application factory paradigm. They were all following good practices, but at the time, I didn't understand WHY they were doing the things they were doing. In these tutorial series, seeing first-hand how the application grows, I was able to see WHY it's necessary to use blueprints and adopt the application factory paradigm. These tutorials are truly awesome!

howards
Автор

By the end of these flask tutorials I finally began to understand Django.

davidyo
Автор

You're an amazing teacher Corey 👍

bugs
Автор

Damn, a tutorial for unit testing from Corey would be a dream come true.

raysun
Автор

Reload the terminal if you get an error around 30:30 people :). Thanks so much Corey for all the great pedagogical work you do.

pedrov
Автор

If like me, you ended up wanting to play with the database after making all the changes that Corey did in this video and didn't know what to do, here is a working solution:

1) Make sure to activate the appropriate virtual environment to work with all needed packages.
2) Open a Python interpreter at the root of your project directory (in the same directory as run.py).
3) Execute the following code (without comments if you wish):

from flaskblog import create_app, db
app = create_app()
# context to run outside the application (no need to launch the server)
ctx = app.app_context()
ctx.push() # start working on database after that command
# Database manipulations here
# ...
ctx.pop() # exit from the app
exit()


As explained on that same page at StackOverflow, you could use a "with" block like so:
"with app.app_context():"
and skip all commands with ctx as shown above, but then you would have to enter everything at once inside the "with" block. If you are going to work directly inside the Python interpreter and not from a script, the first method would be more easy to work with... instead of "with" ;).

slavoie
Автор

I think we all need a t-shirt with the Python logo and "Hey there".

mikec
Автор

I logged in specifically to give you a thumbs up and subscribe. After almost a week of trying to get user login to work with Blueprints I found this video. It helped me solve the problems almost immediately. Thank you.

Brayster
Автор

Watching previous videos I was wondering, why don't we structure our project properly, but you made a separate video on this topic. Amazing! Thanks for your work.

vitalypark
Автор

Loved this series so far! A slight change that I would make that would keep the ENV portion of this within the scope of Python, would be to use the 'dotenv' library, allowing you to keep a custom .env file in your porject folder. That way the entire project remains portable and easily referenced.

wabschall
Автор

I have to say, it was a real pain to switch to blueprints as I had already added a lot more pages to my own app. But I really love how neatly organised it is now and it’s so much easier to find stuff!

IncomeBoost
Автор

I am gonna definitely start supporting you on patreon once I start making money. Idk how to thank you but the amount of stuff that I learn just by watching your videos and practicing is just... incredible. The fact that these videos are accessible for anyone without any kind of payment is just mind blowing.

HACKINGMADEFUN
Автор

Will definitely start contributing once I land a job. You deserve it man!

shauryadhadwal
Автор

I am so grateful to you for this video!! Seriously, for a beginner like me, it can take few years to learn all of this, how to architect your app, how to use different configurations in local development and in production. Thanks a lot! Bless you.

AbhishekNigam
Автор

Learned so much watching these videos. One day when I can, I will contribute to your Patreon.

Pixelaze
Автор

Never done coding before but following your videos I could complete a demo site and successfully deployed on pythonanywhere. A paid course also could not have given me this much knowledge and confidence.

aarkayin
Автор

Great tutorial series! Can't wait for the unit tests for this app tutorial ^^

nickbejan
Автор

Well, it's been about two moths I watch this videos and they are awesome, I build my own app. Thank you very much.

Juanoetdm
Автор

I like the way you start the concepts and unfold gradually to touch every aspects of it. thumbs up

praveenjoshi
Автор

Excellent, this is needed so much to understand Flask. The debugging is excellent.

investmentapps