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!
This! Corey, I would love a video where you talk about how you develop a series like this. How long did the planning take? What was your thought process? And did you try to make everything work as intended before filming these coding sessions? Thanks.
Just for this episode, one really confusing thing for me is WHY he used environment variable in an OS scope. Usually env variables should be scoped to app (because for example we might have many Flask apps running on the same system -> name clashing etc... Also, it's a best practice in other frameworks like Spring boot or Node JS) It just seems so weird for him to do it this way. Could be really confusing for beginners.
And I more clearly understand why I abandoned Django's sprawl and bloat for the _MICRO_-framework Flask. No multi-tiered grandiosity needed just to put up a fully-functioning website for a small business or non-profit. I personally don't see the value of organizing by purpose ("users" and "posts") instead of by function ("routes," "forms," and "models"), especially since you have to have separate routes, forms, and models for each new subpackage--and then also have catchall subpackages like "main" and "util." I also don't see why I should prefer to root around in a now-more complex directory structure when I can just use my editor's search function to jump to the particular @app.route block I want in a traditional views.py or routes.py module. I doubt I'd ever need more than two or three dozen routes anyway, and I do not consider that too many for a single module--frankly it's a relief in a world of ever-more atomized code. Moreover, who wants to see _two_ or more routes.py (or forms.py, etc) tabs open in their editor, each in a different subpackage that is not indicated on the tab. It could happen easily enough in the heat of battle. I get confused enough as it is. So I'm sticking with . . . what shall we call it? Legacy Flask?
@@tcarney57 I didn't even put my code into 'routes', 'forms' , etc. I prefer it to be just one page containing all 1000 lines worth of spaghetti code "_'
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() This explanation comes from StackOverflow here: stackoverflow.com/questions/24060553/creating-a-database-outside-the-application-context 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" ;).
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.
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.
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.
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.
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.
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!
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.
I guess that in this case it makes more sense to test website using Selenium tool, or something similar - but it will be separate topic then.. Hope one day Corey will have inspiration for such a tutorial =)
I have been getting really frustrated doing these tutorials. Not by your fault, but just errors or mistakes of my own. But seeing as I finally finished this one, and only got a couple short videos to go, I feel like I am over the hill in this chapter of learning about flask. Not sure if web design is for me, but at least understanding the fundamentals will help me choose where I want to land in this industry. Basically just wanted to put out a huge thanks. I have been moving super slow through these, but you have set it up in a way that's easy and super digestible. I am currently in the middle of fixing up a Jeep and building a new PC. But as soon as those expenses are done I will definitely be donating to you. I really appreciate what you have done. This is great. Helping people learn is a true gift. Thanks, dude. Consider me subbed and following as long as you keep doing awesome stuff!
what an amazing playlist this is!! In case anyone faces an error like: -> AttributeError: 'NoneType' ....... tip: just close sublime text and refresh after you have secured the database info! also, refresh the terminal after saving the virtual environment variables before you close the terminal window using : pip freeze
At about minute 32:30 after Corey moved the "app..." and the "app.config..." lines into his create_app function he should make one change in the line "app.config..."-line. He should set the value "Config" to "config_class". After that the line reads: "app.config.from_object(config_class)" If he misses this, he cannot use different configurations when calling the run.py funktion. He will always use "Config" instead
@@markzuckerberg6054 Just to clarify - Line 18 (pause at 33:16) is setting a variable config_class in his create_app function. In his function he has set Config to be the default option. When he calls this later he can call it using create_app() which will use the Config as its default option. He can create other configs such as Config1, Config2 etc but in line 20 of his function he should be using config_class instead of Config. Config is just a default value if nothing was passed in when calling the function. Say he does pass in Config1 like create_app(Config1) now it won't work because it is going to only use Config and not look for whatever was passed into the config_class. Hope that makes sense to anyone who was interested.
Hi Corey, Excellent series. Loved it!! One small correction - I think inside the create_app function, the line app.config.from_object(Config) should really be app.config.from_object(config_class). Unless I am missing something. Thanks again!
This tutorial is great. Flask's Blueprint is not. Blueprint in Flask is manual labor with A LOT of traps. You will expend days trying to find out what went wrong with your application when you decide to convert it to blueprint. I almost gave up on Flask when reached that step of coverting my application to blueprint. I didn't do so just because I already had too much work done in it. Those Flask tutoriais should start with blueprints from step one, so people wouldn't go through hell like I did.
hey corey... thx for this awesome quick guide into flask. as i just discovered it for myself it's great to get this nice overview. since i'm still learning python as a hobby i'm struggling in integrating Flask-Admin and Flask-Security to have some basic rights and role management and a nice view for the database. could you please consider adding a part for integrating these extensions too? i think that might be useful for extending this awesome video-tutorial. i'm also very interested in a basic unit-test or selenium-test integration tutorial for this project. also a serializer for an api integration would be awesome... like Flask-Marshmallow... so many ideas but i'm a little to unexperienced to get it all working, all together. this would give me a perfect playgroud to teach myself some new stuff and extend this project for my own needs and learn even more... :D as a very first customization i was able to integrate ckeditor for the TextArea in the Post.Content... this might be usefull for others to... perhaps another video idea for you and this series. my next plans are rights and roles, testing, add images for Posts, categories and tags and of course some other post-types, like pages or media view. thank you for inspiring me with every video you post... that i wanted to post under very of your videos... but this seems a little childish :D really dude... thank you very much... you teached me very well. some coins for more coffee are on the way :)
Thanks for this amazing series of Flask, Corey. I was so thankful that i saw your channel in the beginning of my study journey. Your videos are really easy to understand and You are an amazing teacher for me . Really thanks again for your time and hardwork to make these videos. May God Bless you ...
Thank God for Github. I do a commit after each video in this series once I'm confident that the application works. I could not get this one to work after doing the last 'import config' stuff in the last third of the video, so I deleted all the files and ran a $git restore --hard command and got everything back to the way it was at the end of Part 10. Off to redo this video! Edit: in process of redoing the video. A good spot to set up a git commit is at around 23:14, right after changing the login_manager.login_view variable. Make sure that you can run the app and all the routes work using the new Blueprints before commiting.
MAN! kkkkkkkkk it was reeeealy anoying to change all the routes and check in my aplication, but i have to thank you for the amazing videos. You really helped me in my career
if you get a runtimeerror like A secret key is required to use CSRF, then you need to close your commendline, open a new one and start the server again, the new cmd will know about the environment variables you just set
hey corey! loving this series this is my first time using python and flask and really loving it :) just wondering are you going to do a tutorial on unit testing? kind of confuses me and would love to see how its done, again great work thank you!!
I spent about 30min learning regular expressions using Google (duck duck go for privacy :) ), which was very useful for the find and replace to update the url_for() usage! I recommend this as it's now a powerful tool I have for use in future programming challenges! I used: url_for[\(]'[[:alnum:]]*' and; url_for[\(]'[[:alnum:]]*.[[:alnum:]]*' These two find either; the original form of the function before part 11, and, the new form with an added object (and connecting dot). I'm using Notepad++ which has regular expression search. Use google to learn regular expressions for your particular editor. EDIT: my expressions missed out functions that had underscores in them. It's easily fixed though once you know the syntax.
Love the videos, but I think creating these apps should be done this way from the start--"There should be one-- and preferably only one --obvious way to do it."---no matter the size of the app--"Special cases aren't special enough to break the rules"---size should not matter....that way, they can grow without having to refactoring anything. I really wish someone with the knowledge would create a tutorial doing it using the Factory App pattern with Blueprints from the get go. I would if I had that knowledge, but I don't. Still these are GREAT videos and many thanks to you for creating them.
I really love your lectures 💕 ❤ 💖 corey..u r the best I've seen..may God bless you with and Good health and wealth u wish for 🙏 ❤ ....and we expect you to continue to share your knowledge on other languages and courses too possibly
if you have problem with db.drop_all() or db.create_all() try this : from yourapp import db, create_app >>> db.create_all(app=create_app()) or >>> db.drop_all(app=create_app()) this will help u :)
Thank you so much! Saved me hours of searching around. This was my code for db function (put in run.py): from flaskblog import db, create_app app = create_app() if __name__ == '__main__': app.run(debug=True) db.create_all(app) # Or db.drop_all(app)
Hey, Corey, thank you very much! Awesome videos and I learned a lot, ... by the way, have you made the unit test video yet? really looking forward to it.
you can also ignore directories when using the tree command by using the -I switch (that is a capital i like in ice). Use the | (pipe character) to separate multiple directories. for example, i use this one listed below to ignore pycache and profile pics directories: tree -I '__pycache__|profile_pics'
Is it really best practice storing sensitive information like passwords in system environment variables? I'm sure it's better than putting it directly into the code, but it still leaves them lying around for anyone who has access to your computer and happens to look there. Anyway, this series is terrific, thank you so much!
If you happen to delete the site.db and want to add your own db, you can add the following code to your run.py: from flaskblog import create_app from flaskblog import db app = create_app() with app.app_context(): db.create_all() db.session.commit() if __name__ == '__main__': app.run(debug=True) My rationale for adding this to the run.py is the following (and I might the wrong). The app is created using the factory pattern: since we use app_context(), the db is created within the context correct app. You could run this inside the __init__.py, but you will get circular import references so you would have to do ugly imports at the bottom of the __init__.py just before return app. If there is no file called site.db in your flaskblog folder, the above code will create it. If there is a site.db file, it will ignore the code. If you don't initialize the db after creating the app, your app will crash when you call it in the browser as the following statement in the home route cannot execute on an empty posts table. posts = Post.query.order_by( Post.date_posted.desc()).paginate(page=page, per_page=5) The error you will get without the db initialization added to run.py is the following: sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) no such table: post [SQL: SELECT post.id AS post_id, post.title AS post_title, post.date_posted AS post_date_posted, post.content AS post_content, post.user_id AS post_user_id FROM post ORDER BY post.date_posted DESC LIMIT ? OFFSET ?] [parameters: (5, 0)] (Background on this error at: sqlalche.me/e/14/e3q8) You could probably also condition on the posts table being available and then pass on empty posts to the template in your home route, if the condition is not met, but I think it's not required or not as clean.
Hi, I love this series. I think I found a problem in the __init__.py file at the create_app function. It should be "app.config.from_object(config_class)" not "app.config.from_object(Config)".
Hello Corey, I am learning from your video and am at this tutorial about blueprints. I have a question for you, as there is a lot of changes made from the prior structure of files, folders, forms, users, etc to a new system called blueprints, 1. Why didn’t you follow up from the beginning? I can understand why, but want to know your answer & 2. From here on, if I start a different project with flask, should I use blueprints model from the beginning? Please answer. TIA & great content.
Thank you for the thorough and detailed explanation on this series, Corey! I have a question now that we have separated the instantiation of the application into a function so that we can create multiple instances of that function with different configuration. However, I am lost as to how to add another column to the `site.db` SQLAlchemy database after I added another column to the `User` model where the additional column is `last_reset_request = db.Column(db.DateTime, nullable=False, default=datetime.utcnow)`. Thank you.
Thank you for the tutorials Corey! Got a noob (hopefully not really a dumb) question here, is the web app a microservices based (or microservices architecture)? Thank you !
Great series and Im learning a ton! He mentioned multiple application for testing and one for production. Im assuming that after watching this video I can create multiple "Config" classes and run those as my app, one for testing and one for production?
Please let me know if this is wrong!! : I was having trouble getting Flask to run again, I kept getting an Attribute Error because the database address had been moved into an environment variable. I tried following Corey's video on Env Var but it didn't work for me on Ubuntu 19. Instead of editing ~/.bash_profile I needed to edit ~/.bashrc. Add you variables to the top of that file, save and reload and you should be good. And thank you Corey, you're an amazing teacher; always straight to the point.
FYI init_app() - this method is written inside each extension. The init_app method exists so that the extension object (e.g. flask_login object) can be instantiated without requiring an app object. flask.pocoo.org/docs/1.0/extensiondev/
instead of using the variable name 'current_app' everywhere, can you make alias in the import section? something like from flaskblog import current_app as app?
absolutely great tutorial !!!! thank you so much. I have a problem at the end all was great and i am getting this error . AttributeError: 'NoneType' object has no attribute 'drivername' i couldn't figure out at all . I try to change the config. file the same problem . can you help ? thanks again
I had the same problem. The exports from the bash profile aren't exporting. I am not familiar with it, and I couldn't figure it out . So I left the SECRET_KEY and SQLALCHEMY_DATABASE_URI untouched in class Config in my config.py file. Like this: import os class Config: SECRET_KEY = '5791628bb0b13ce0c301dfde280ba245' SQLALCHEMY_DATABASE_URI = 'sqlite:///site.db' MAIL_SERVER = 'smtp.googlemail.com' MAIL_PORT = 587 MAIL_USE_TLS = True MAIL_USERNAME = 'clariceloveslambs@gmail.com' MAIL_PASSWORD = 'xkdjsdkdkddhe' The application should run fine now, obviously the SECRET_KEY and SQLALCHEMY_DATABASE_URI are not hidden in this workaround. Edit: You can watch this quick tutorial from Corey. Quick and easy. Python Quick Tip: Hiding Passwords and Secret Keys in Environment Variables (Mac & Linux) ruclips.net/video/5iWhQWVXosU/видео.html
I closed the terminal and reset the environment variables with different names. It worked fine then. I am working on windows. Every time you close the terminal you'll have to reset the env variables as they are stored temporarily.
This is one of the best tutorial I have ever been enrolled. I have just one question. After the Blueprint section, now if go to terminal after typing python. I am getting issue while connecting to the database from the command line. I am typing "from flaskblog import db". then I am not able to get in or query anything.
See J Town's comment. He says: >>> from flaskblog import create_app >>> from flaskblog._init_ import db >>> from flaskblog.models import current_app, User, Post >>> app = create_app() >>> app.app_context().push() >>> print (app) # Now you can run queries against your database. >>> User.query.all() >>> Post.query.all()
Also, please post some lectures on how to build system with Post and comments relationships. Like you can start with Per post many comments which can be seen on home page
Your tutorials are amazing and unique! as a newbie, I am wondering how to regenerate the database in this stage that app is created inside create_app(Config) method?
Hello Corey, thank you very much! You are an amazing teacher. I have a question. I have followed your tutorial so far, and I am trying to evolve my website a bit more. I am trying to use DispatcherMiddleware to connect another flask app to my application. The new flask app is a dashboard built with dash. I am having an issue calling the app instance (of the app = create_app()) to my main python script. Is there any way to retrieve this instance so I can use the DispatcherMiddleware? Thank you!
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!
This! Corey, I would love a video where you talk about how you develop a series like this. How long did the planning take? What was your thought process? And did you try to make everything work as intended before filming these coding sessions? Thanks.
totally agree, this is what the internet is missing.
Just for this episode, one really confusing thing for me is WHY he used environment variable in an OS scope. Usually env variables should be scoped to app (because for example we might have many Flask apps running on the same system -> name clashing etc... Also, it's a best practice in other frameworks like Spring boot or Node JS)
It just seems so weird for him to do it this way. Could be really confusing for beginners.
By the end of these flask tutorials I finally began to understand Django.
😂😂😂,same to me
And I more clearly understand why I abandoned Django's sprawl and bloat for the _MICRO_-framework Flask. No multi-tiered grandiosity needed just to put up a fully-functioning website for a small business or non-profit. I personally don't see the value of organizing by purpose ("users" and "posts") instead of by function ("routes," "forms," and "models"), especially since you have to have separate routes, forms, and models for each new subpackage--and then also have catchall subpackages like "main" and "util." I also don't see why I should prefer to root around in a now-more complex directory structure when I can just use my editor's search function to jump to the particular @app.route block I want in a traditional views.py or routes.py module. I doubt I'd ever need more than two or three dozen routes anyway, and I do not consider that too many for a single module--frankly it's a relief in a world of ever-more atomized code. Moreover, who wants to see _two_ or more routes.py (or forms.py, etc) tabs open in their editor, each in a different subpackage that is not indicated on the tab. It could happen easily enough in the heat of battle. I get confused enough as it is. So I'm sticking with . . . what shall we call it? Legacy Flask?
LOL
Same to me here. I am just as amazed!!!!! And I am loving flask more
@@tcarney57 I didn't even put my code into 'routes', 'forms' , etc. I prefer it to be just one page containing all 1000 lines worth of spaghetti code "_'
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()
This explanation comes from StackOverflow here: stackoverflow.com/questions/24060553/creating-a-database-outside-the-application-context
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" ;).
Thanks so much for this!
Thank you for saving my life!
Thanks Sebastien... This helped a lot
My god you saved my life. I spent the better half of an entire day searching for this..... LOL Corey upvote this!
Would you know how to add migrations to it? I cant figure it out..
You're an amazing teacher Corey 👍
Damn, a tutorial for unit testing from Corey would be a dream come true.
Reload the terminal if you get an error around 30:30 people :). Thanks so much Corey for all the great pedagogical work you do.
cheers! This happened to me!
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.
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.
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.
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.
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.
I think we all need a t-shirt with the Python logo and "Hey there".
How it's going everybody
😂😂😂
"In this tutorial, we're gonna look at..."😂😂
So let's get started.
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!
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.
Glad it helped!
this 'blueprint' video is the best intro to understanding Django.
Will definitely start contributing once I land a job. You deserve it man!
I like the way you start the concepts and unfold gradually to touch every aspects of it. thumbs up
Great tutorial series! Can't wait for the unit tests for this app tutorial ^^
I guess that in this case it makes more sense to test website using Selenium tool, or something similar - but it will be separate topic then.. Hope one day Corey will have inspiration for such a tutorial =)
Well, it's been about two moths I watch this videos and they are awesome, I build my own app. Thank you very much.
Best playlist ever. Thank you very much. can't imagine how much people spend outside to learn this which even not as good as yours.
Excellent, this is needed so much to understand Flask. The debugging is excellent.
Learned so much watching these videos. One day when I can, I will contribute to your Patreon.
I have been getting really frustrated doing these tutorials. Not by your fault, but just errors or mistakes of my own. But seeing as I finally finished this one, and only got a couple short videos to go, I feel like I am over the hill in this chapter of learning about flask. Not sure if web design is for me, but at least understanding the fundamentals will help me choose where I want to land in this industry. Basically just wanted to put out a huge thanks. I have been moving super slow through these, but you have set it up in a way that's easy and super digestible. I am currently in the middle of fixing up a Jeep and building a new PC. But as soon as those expenses are done I will definitely be donating to you. I really appreciate what you have done. This is great. Helping people learn is a true gift. Thanks, dude. Consider me subbed and following as long as you keep doing awesome stuff!
Oh man you don't have any idea how many times your videos saved my ass, in the college and now in my job, thanks man
what an amazing playlist this is!!
In case anyone faces an error like:
-> AttributeError: 'NoneType' .......
tip: just close sublime text and refresh after you have secured the database info!
also, refresh the terminal after saving the virtual environment variables before you close the terminal window using : pip freeze
When I get job the very first thing I ll do to support this amazing channel & thank you so very much
Very clear and good explanations. Best Python and Flask tutorials ever!
Windows users! If you get:
```error of 'NoneType' object has no attribute 'drivername',```
Check if you restarted your terminal :)
hah. thanks. that solved that error :)
Happened to me on linux too.
This happens on Mac too - If possible you should edit comment to remove "Windows users!" since it applies to everyone :)
I had to restart Firefox and the whole Anaconda Navigator in order to work
I wish I searched for this comment 20 min earlier... THANK YOU
At about minute 32:30 after Corey moved the "app..." and the "app.config..." lines into his create_app function he should make one change in the line "app.config..."-line. He should set the value "Config" to "config_class". After that the line reads: "app.config.from_object(config_class)"
If he misses this, he cannot use different configurations when calling the run.py funktion. He will always use "Config" instead
what do you mean?
@@markzuckerberg6054 Just to clarify - Line 18 (pause at 33:16) is setting a variable config_class in his create_app function. In his function he has set Config to be the default option. When he calls this later he can call it using create_app() which will use the Config as its default option. He can create other configs such as Config1, Config2 etc but in line 20 of his function he should be using config_class instead of Config. Config is just a default value if nothing was passed in when calling the function. Say he does pass in Config1 like create_app(Config1) now it won't work because it is going to only use Config and not look for whatever was passed into the config_class. Hope that makes sense to anyone who was interested.
Hi Corey,
Excellent series. Loved it!!
One small correction - I think inside the create_app function, the line app.config.from_object(Config) should really be app.config.from_object(config_class). Unless I am missing something.
Thanks again!
Yes, you are correct. Someone else pointed that out as well. I will issue a correction in the next video I put out on this series. Thanks again!
This tutorial is great.
Flask's Blueprint is not.
Blueprint in Flask is manual labor with A LOT of traps. You will expend days trying to find out what went wrong with your application when you decide to convert it to blueprint.
I almost gave up on Flask when reached that step of coverting my application to blueprint. I didn't do so just because I already had too much work done in it.
Those Flask tutoriais should start with blueprints from step one, so people wouldn't go through hell like I did.
hey corey... thx for this awesome quick guide into flask. as i just discovered it for myself it's great to get this nice overview.
since i'm still learning python as a hobby i'm struggling in integrating Flask-Admin and Flask-Security to have some basic rights and role management and a nice view for the database.
could you please consider adding a part for integrating these extensions too? i think that might be useful for extending this awesome video-tutorial.
i'm also very interested in a basic unit-test or selenium-test integration tutorial for this project.
also a serializer for an api integration would be awesome... like Flask-Marshmallow... so many ideas but i'm a little to unexperienced to get it all working, all together.
this would give me a perfect playgroud to teach myself some new stuff and extend this project for my own needs and learn even more... :D
as a very first customization i was able to integrate ckeditor for the TextArea in the Post.Content... this might be usefull for others to... perhaps another video idea for you and this series.
my next plans are rights and roles, testing, add images for Posts, categories and tags and of course some other post-types, like pages or media view.
thank you for inspiring me with every video you post... that i wanted to post under very of your videos... but this seems a little childish :D
really dude... thank you very much... you teached me very well. some coins for more coffee are on the way :)
Thanks for this amazing series of Flask, Corey. I was so thankful that i saw your channel in the beginning of my study journey. Your videos are really easy to understand and You are an amazing teacher for me . Really thanks again for your time and hardwork to make these videos. May God Bless you ...
if a tutorial is too good to be true, its probably Corey's
Thanks!
While re-organizing I'm reviewing all my routes and templates. It's a good time to step through the code and workflows.
Thanks for this awesome tutorial!!!
Just wondering that will there be a video talking about how to do unit testing for this application?
Massive thumbs up Corey!
After I'll get a new job - I promise you'll be the first one to get a good part of my first salary.
the best tutorial in my life
Thank God for Github. I do a commit after each video in this series once I'm confident that the application works.
I could not get this one to work after doing the last 'import config' stuff in the last third of the video, so I deleted all the files and ran a $git restore --hard command and got everything back to the way it was at the end of Part 10.
Off to redo this video!
Edit: in process of redoing the video. A good spot to set up a git commit is at around 23:14, right after changing the login_manager.login_view variable. Make sure that you can run the app and all the routes work using the new Blueprints before commiting.
MAN! kkkkkkkkk it was reeeealy anoying to change all the routes and check in my aplication, but i have to thank you for the amazing videos. You really helped me in my career
really learned a lot from this series
Thank you so much for these tutorials Corey
if you get a runtimeerror like A secret key is required to use CSRF, then you need to close your commendline, open a new one and start the server again, the new cmd will know about the environment variables you just set
Thx for pointing that out, saved me from wasting hour+ on debugging a dead end :D
hey corey! loving this series this is my first time using python and flask and really loving it :) just wondering are you going to do a tutorial on unit testing? kind of confuses me and would love to see how its done, again great work thank you!!
Wow, what a fantastic video. This stuff makes so much more sense.
did that unittest video for these kinds of applications ever get posted?
Sir i want to thank you so much for the video you done all
just repeating every other comment: what a great series
We should’ve done this from the start 😭😭 so much extra work
Looking forward to the Unit Testing
Did he ever make one?
This tutorial is so good! Thanks!
I spent about 30min learning regular expressions using Google (duck duck go for privacy :) ), which was very useful for the find and replace to update the url_for() usage! I recommend this as it's now a powerful tool I have for use in future programming challenges!
I used: url_for[\(]'[[:alnum:]]*'
and;
url_for[\(]'[[:alnum:]]*.[[:alnum:]]*'
These two find either; the original form of the function before part 11, and, the new form with an added object (and connecting dot).
I'm using Notepad++ which has regular expression search. Use google to learn regular expressions for your particular editor.
EDIT: my expressions missed out functions that had underscores in them. It's easily fixed though once you know the syntax.
Keep up the good work. Your videos are amazing.
Good one. Thanks ! One suggestion is you should have started the app with blueprints and then add apps ...
Thanks you very much for a great tutorial. I realy appreciate your work.
This is an excellent series. Thanks.
Great video, thanks a lot for your lessons! Looking forward for unit test videos for this website )))
Just 1 more video for me. Great vids. So much information.
Love the videos, but I think creating these apps should be done this way from the start--"There should be one-- and preferably only one --obvious way to do it."---no matter the size of the app--"Special cases aren't special enough to break the rules"---size should not matter....that way, they can grow without having to refactoring anything.
I really wish someone with the knowledge would create a tutorial doing it using the Factory App pattern with Blueprints from the get go. I would if I had that knowledge, but I don't.
Still these are GREAT videos and many thanks to you for creating them.
I really love your lectures 💕 ❤ 💖 corey..u r the best I've seen..may God bless you with and Good health and wealth u wish for 🙏 ❤ ....and we expect you to continue to share your knowledge on other languages and courses too possibly
Thank You for this video series.
It was a mega help!
19:50 For PyCharm users on Mac, >>Edit >>Copy>>Copy Path>>Absolute Path>>Edit>>Find>>Find in Path
if you have problem with db.drop_all() or db.create_all() try this :
from yourapp import db, create_app
>>> db.create_all(app=create_app()) or
>>> db.drop_all(app=create_app())
this will help u :)
Thank you so much! Saved me hours of searching around. This was my code for db function (put in run.py):
from flaskblog import db, create_app
app = create_app()
if __name__ == '__main__':
app.run(debug=True)
db.create_all(app) # Or db.drop_all(app)
Hey, Corey, thank you very much! Awesome videos and I learned a lot, ... by the way, have you made the unit test video yet? really looking forward to it.
I really like your videos. Thanks very much
you can also ignore directories when using the tree command by using the -I switch (that is a capital i like in ice). Use the | (pipe character) to separate multiple directories. for example, i use this one listed below to ignore pycache and profile pics directories:
tree -I '__pycache__|profile_pics'
Is it really best practice storing sensitive information like passwords in system environment variables? I'm sure it's better than putting it directly into the code, but it still leaves them lying around for anyone who has access to your computer and happens to look there.
Anyway, this series is terrific, thank you so much!
I had the same question lol
If you happen to delete the site.db and want to add your own db, you can add the following code to your run.py:
from flaskblog import create_app
from flaskblog import db
app = create_app()
with app.app_context():
db.create_all()
db.session.commit()
if __name__ == '__main__':
app.run(debug=True)
My rationale for adding this to the run.py is the following (and I might the wrong). The app is created using the factory pattern: since we use app_context(), the db is created within the context correct app. You could run this inside the __init__.py, but you will get circular import references so you would have to do ugly imports at the bottom of the __init__.py just before return app.
If there is no file called site.db in your flaskblog folder, the above code will create it. If there is a site.db file, it will ignore the code. If you don't initialize the db after creating the app, your app will crash when you call it in the browser as the following statement in the home route cannot execute on an empty posts table.
posts = Post.query.order_by(
Post.date_posted.desc()).paginate(page=page, per_page=5)
The error you will get without the db initialization added to run.py is the following:
sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) no such table: post
[SQL: SELECT post.id AS post_id, post.title AS post_title, post.date_posted AS post_date_posted, post.content AS post_content, post.user_id AS post_user_id
FROM post ORDER BY post.date_posted DESC
LIMIT ? OFFSET ?]
[parameters: (5, 0)]
(Background on this error at: sqlalche.me/e/14/e3q8)
You could probably also condition on the posts table being available and then pass on empty posts to the template in your home route, if the condition is not met, but I think it's not required or not as clean.
Work as advertised. Thanks
Hi, I love this series. I think I found a problem in the __init__.py file at the create_app function. It should be "app.config.from_object(config_class)" not "app.config.from_object(Config)".
Hello Corey, I am learning from your video and am at this tutorial about blueprints. I have a question for you, as there is a lot of changes made from the prior structure of files, folders, forms, users, etc to a new system called blueprints, 1. Why didn’t you follow up from the beginning? I can understand why, but want to know your answer & 2. From here on, if I start a different project with flask, should I use blueprints model from the beginning? Please answer. TIA & great content.
I got the question answered in the end of this video, thanks. Your the best man.
heytherehowsitigoingeverybody
remember to return the app at the end if you get the error NoneType has no attribute run
Great and Superb ....nothing less
Thank you for the thorough and detailed explanation on this series, Corey! I have a question now that we have separated the instantiation of the application into a function so that we can create multiple instances of that function with different configuration. However, I am lost as to how to add another column to the `site.db` SQLAlchemy database after I added another column to the `User` model where the additional column is `last_reset_request = db.Column(db.DateTime, nullable=False, default=datetime.utcnow)`. Thank you.
Thank you for the tutorials Corey! Got a noob (hopefully not really a dumb) question here, is the web app a microservices based (or microservices architecture)? Thank you !
It is all very confusing, I couldn't really figure out what is happening in this video. The rest of your flask tutorials are golden.
Great series and Im learning a ton!
He mentioned multiple application for testing and one for production. Im assuming that after watching this video I can create multiple "Config" classes and run those as my app, one for testing and one for production?
Please let me know if this is wrong!! : I was having trouble getting Flask to run again, I kept getting an Attribute Error because the database address had been moved into an environment variable. I tried following Corey's video on Env Var but it didn't work for me on Ubuntu 19. Instead of editing ~/.bash_profile I needed to edit ~/.bashrc. Add you variables to the top of that file, save and reload and you should be good. And thank you Corey, you're an amazing teacher; always straight to the point.
FYI
init_app() - this method is written inside each extension. The init_app method exists so that the extension object (e.g. flask_login object) can be instantiated without requiring an app object.
flask.pocoo.org/docs/1.0/extensiondev/
instead of using the variable name 'current_app' everywhere, can you make alias in the import section? something like from flaskblog import current_app as app?
did the same thing
Yep, and it works perfectly
Amazing tutorial! Very understandable, great explanations.
absolutely great tutorial !!!! thank you so much. I have a problem at the end all was great and i am getting this error . AttributeError: 'NoneType' object has no attribute 'drivername' i couldn't figure out at all . I try to change the config. file the same problem . can you help ? thanks again
I had the same problem. The exports from the bash profile aren't exporting. I am not familiar with it, and I couldn't figure it out . So I left the SECRET_KEY and SQLALCHEMY_DATABASE_URI untouched in class Config in my config.py file.
Like this:
import os
class Config:
SECRET_KEY = '5791628bb0b13ce0c301dfde280ba245'
SQLALCHEMY_DATABASE_URI = 'sqlite:///site.db'
MAIL_SERVER = 'smtp.googlemail.com'
MAIL_PORT = 587
MAIL_USE_TLS = True
MAIL_USERNAME = 'clariceloveslambs@gmail.com'
MAIL_PASSWORD = 'xkdjsdkdkddhe'
The application should run fine now, obviously the SECRET_KEY and SQLALCHEMY_DATABASE_URI are not hidden in this workaround.
Edit:
You can watch this quick tutorial from Corey. Quick and easy.
Python Quick Tip: Hiding Passwords and Secret Keys in Environment Variables (Mac & Linux)
ruclips.net/video/5iWhQWVXosU/видео.html
I closed the terminal and reset the environment variables with different names. It worked fine then. I am working on windows. Every time you close the terminal you'll have to reset the env variables as they are stored temporarily.
This is one of the best tutorial I have ever been enrolled.
I have just one question. After the Blueprint section, now if go to terminal after typing python. I am getting issue while connecting to the database from the command line. I am typing "from flaskblog import db". then I am not able to get in or query anything.
Were you able to solve this I am having the same issue
See J Town's comment. He says:
>>> from flaskblog import create_app
>>> from flaskblog._init_ import db
>>> from flaskblog.models import current_app, User, Post
>>> app = create_app()
>>> app.app_context().push()
>>> print (app)
# Now you can run queries against your database.
>>> User.query.all()
>>> Post.query.all()
Also, please post some lectures on how to build system with Post and comments relationships. Like you can start with Per post many comments which can be seen on home page
excellent content, Corey!
You are amazing teacher thank you for flask tutorieal
the impression i got from watching this video after finishing django is like "how to make django application with flask"
Your tutorials are amazing and unique! as a newbie, I am wondering how to regenerate the database in this stage that app is created inside create_app(Config) method?
did you every make a video on unit testing this application?
testing video please
We appreciate
amazing thank you again
A nice way to display tree structure with colors ignoring __pycache__ is via:
$ tree -C -I __pycache__
-C stands color
-I stands for ignore
Please do a unittest video. it will be very helpful
Hey Corey, Great Tutorials!! Waiting for db migration from SQLite to Postgres/MySQL !!!!
great tutorial, Corey. it gives a lot of new insights, Thank you very much. and are waiting for the unit testing video ^_^
Good thank you ,
So, I can build a large projects by just this bleuprint ?
Hello Corey, thank you very much! You are an amazing teacher. I have a question. I have followed your tutorial so far, and I am trying to evolve my website a bit more. I am trying to use DispatcherMiddleware to connect another flask app to my application. The new flask app is a dashboard built with dash.
I am having an issue calling the app instance (of the app = create_app()) to my main python script. Is there any way to retrieve this instance so I can use the DispatcherMiddleware? Thank you!
This is basically a gold mine