▶️ Watch Entire Flask Playlist ✅ Subscribe To My RUclips Channel: bit.ly/2TU96lm bit.ly/2IGzvOR ▶️ See More At: ✅ Join My Facebook Group: Codemy.com bit.ly/2GFmOBz ▶️ Learn to Code at Codemy.com ✅ Buy a Codemy T-Shirt! Take $30 off with coupon code: youtube1 bit.ly/2VC9WUN
I get the following error a 11min in when you are using the gitbash terminal to create the "db ImportError: cannot import name 'db' from 'app' (C:\my_flask\app.py)"
from flask import Flask, render_template, request #import smtplib from flask_sqlalchemy import SQLAlchemy from datetime import datetime app = Flask(__name__) app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///friends.db' #Initialize the database db = SQLAlchemy(app) #Create db model class Friends(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(200), nullable=False) date_created = db.Column(db.DateTime, default=datetime.utcnow) #Create a function to return a string when we add something def __repr__(self): return "" % self.id
Say that your friends.html page has multiple types of input and you had another .html page that has only one input variable that also posts to your friends.html. If you were to have two different .html pages going to your friends.html with the post method, how could you distinguish between them? Say, friends.html would update the database and itself but the other .html would bring only a friends name and you were to have a dropdown menu which default value needs to be that posted friends name. How would you do that?
Because no, imports are harder with those things lol what could be easier than the way I do it now? I don't have to fudge with VSCode or Pycharm settings or installation hassles.
I'm currently at 12:20 and I've followed all of these steps and get errors so I've decided to follow some troubleshooting steps on StackOverflow to the point where.I do db.create_all() I get no errors. However, for some reason the database doesn't appear on my file explorer nor my IDE project explorer (PyCharm). Has the database been created? Thanks. UPDATE - can confirm the database was created as searched for 'friends.db' in finder on Mac.
Two things: 1. If you follow along with the videos, you won't need to troubleshoot. You're having errors because you aren't following the directions. Just to be blunt. Just rewatch the videos and try again. 2. Sorry, I don't use pycharm or recommend it (for this reason). So I can't guess why it is doing what it's doing. Just use the tools I use. They're free.
@@Codemycom thanks for the reply. I can reassure you I have followed all directions and am just using a different IDE. Not saying it’s an issue with your tutorial but rather may be a common error when people watch this video if they are using an IDE such as PyCharm so just pointing it out in the comments. The main error was the Python terminal couldn’t find Flask for some reason.
@@cricketer1987 Yeah it could be Pycharm...but also...I get hundreds of comments and emails from people SWEARING that they followed the directions...then later saying "oh, whoops, I left out a comma". If it didn't work, it's likely because you missed something. It's no big deal, we all do it.
@Nezhat Nour >>> db.create_all() Traceback (most recent call last): File "", line 1, in NameError: name 'db' is not defined This error still pops up after
If I made a User model and created it via de Python Interpreter. How can I add a new rows? For example, if you wanted to add a row 'Gender' to your existing database after you did the command db.create_all()?
i'm on mac osx and having trouble using "winpty python". is there a mac version of this command or do i have to take extra steps to install the necessary libraries for this command?
I am not able to display the information after submitting the form. Can you tell me where I could be wrong? I followed the video step by step but instead I just used more variables than just a name.
@@Codemycom I figured it out. In my case, I created multiple columns in the DB, hence to fetch data from it, i need to specify the column name (record.column1, record.column2), otherwise it will just give me etc which representing the whole row of record
can you help me with my css, i write this on my code when i change background to blue (from the previous tutorial) it changed, but when i want to change it to white in this tutorial, it wont change, and stay at dark blue, even when i deleted the css file it still doesnt change, my background still dark blue :'(
@@Codemycom umm, i got problem again :'( pls help, i use flash messages, so when i want to insert data it will show a flash messages, i can fill my flash messages, but it doesn't show up 😭, i'm still learning so i don't have money to learn from many source :'(
@@Codemycom okk thankyouuu my fav youtuber, i already fix it, anyway i tried ur code, and when i run it, flask doesn't run, it just showed like this: flask run (virtual) without showing any errors or server
@@Codemycom I'm just think that if DB connection crashes if you just rereun the flask app.py (or whatever) it would create the database. I would have thought the gitbash command to create the database can be directly embedded in the flask file code. Obviously not.
I'm having an error when tyring to import db >>> from app import db C:\Users\user\AppData\Local\Programs\Python\Python310\lib\site-packages\flask_sqlalchemy\__init__.py:851: UserWarning: Neither SQLALCHEMY_DATABASE_URI nor SQLALCHEMY_BINDS is set. Defaulting SQLALCHEMY_DATABASE_URI to "sqlite:///:memory:". Can someone help me pls?
Not showing my database c:\users\medion\desktop\wb env\virtual\lib\site-packages\flask_sqlalchemy\__init__.py:812: UserWarning: Neither SQLALCHEMY_DATABASE_URI nor SQLALCHEMY_BINDS is set. Defaulting SQLALCHEMY_DATABASE_URI to "sqlite:///:memory:". warnings.warn( EDIT:never mind i forgot the A in DATABASE
@@Codemycom Hi there. I have the same error message as Akram, but I am fairly certain that I have spelt everything correctly. Is there any other possible issues? Thanks!
What is the best way to add multiple user inputs as far as the db.session.add is concerned in the app.py file? i.e. db.session.add(this_db_column, that_db_column, this_other_db_column)
sir kindly help me i'm getting error: sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) unable to open database file (Background on this error at: sqlalche.me/e/13/e3q8)
can you create tutorial on simple user management system in flask api something like this ------------------------- I have the following tables: Table name= group Attributes: id name Here simply the group is created. ------------------------------------------------------------------------------ Table name = group permission Attributes: id group_id Permission_id Here simply the permission for the group is assigned ----------------------------------------------------------------------------- Table name =permission Attributes: id name code name Here permission is created Table name =user Attributes: id username password ------------------------------------------------------------------------------- Here the user is created Table name =user_groups Attributes: Id User_id Group_id Here the group for the user is assigned and all the permission inside this group should also be assigned to that user -------------------------------------------------------------------------------------------------------------------------- Table name =user_permission Attributes: Id User_id Permission_id Here the user might get more permission other than the permission assigned from the group. For example, if the user has only access for reading and writes from it’s defined group then if the admin user wants then he/she can directly assign permission to access a certain menu to the specific user without assigning to the other user of the same group. I haven't seen anyone on youtube have done this stuff
Thanks a lot for the tutorial. However, I meet sqlalchemy.exe.OperationalError: (sqlite3.OperationalError) no such column when I try the same steps you showed. Could I know what is the potential thing that I missed here? Thanks a lot!
▶️ Watch Entire Flask Playlist ✅ Subscribe To My RUclips Channel:
bit.ly/2TU96lm bit.ly/2IGzvOR
▶️ See More At: ✅ Join My Facebook Group:
Codemy.com bit.ly/2GFmOBz
▶️ Learn to Code at Codemy.com ✅ Buy a Codemy T-Shirt!
Take $30 off with coupon code: youtube1 bit.ly/2VC9WUN
Do you have a Patreon page?
@@JoshKonoff1 No, but you can sign up for a membership at my website Codemy.com
Just thought i'd thank you for carrying me through one of my CS assignments, cheers, I'd be in the bin without these videos
Happy to help!
This force is very strong with this one. Indeed a Jedi of his craft. Indeed is he.
lol thanks!
I had problems with understanding flask, You made it so easy for me. I now get it .. From the botom of my heart, Thank you... Happy new year
You're welcome! Happy New Year!
I had been waiting for this video for so long, finally
Glad you liked it!
Man i love your flask videos
Thanks!
very simple and easy to follow tutorial, thank you very much
very welcome!
I get the following error a 11min in when you are using the gitbash terminal to create the "db ImportError: cannot import name 'db' from 'app' (C:\my_flask\app.py)"
from flask import Flask, render_template, request
#import smtplib
from flask_sqlalchemy import SQLAlchemy
from datetime import datetime
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///friends.db'
#Initialize the database
db = SQLAlchemy(app)
#Create db model
class Friends(db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(200), nullable=False)
date_created = db.Column(db.DateTime, default=datetime.utcnow)
#Create a function to return a string when we add something
def __repr__(self):
return "" % self.id
Thank you for sharing your knowledge Sir we love you
Say that your friends.html page has multiple types of input and you had another .html page that has only one input variable that also posts to your friends.html. If you were to have two different .html pages going to your friends.html with the post method, how could you distinguish between them? Say, friends.html would update the database and itself but the other .html would bring only a friends name and you were to have a dropdown menu which default value needs to be that posted friends name. How would you do that?
Finnaly some databases tnx man
Sure thing
Hi, thanks for your easy-to-follow videos, could you do a video for searching through a database with Flask?
Glad you're enjoying them! I might do something like that in the future...
Explained really clearly, thanks alot!
Glad it helped!
Quite Informative, Any reason why you're not using PyCharm or VSCode, would make life easier with imports etc..,
Because no, imports are harder with those things lol what could be easier than the way I do it now? I don't have to fudge with VSCode or Pycharm settings or installation hassles.
I'm currently at 12:20 and I've followed all of these steps and get errors so I've decided to follow some troubleshooting steps on StackOverflow to the point where.I do db.create_all() I get no errors. However, for some reason the database doesn't appear on my file explorer nor my IDE project explorer (PyCharm). Has the database been created? Thanks. UPDATE - can confirm the database was created as searched for 'friends.db' in finder on Mac.
Two things:
1. If you follow along with the videos, you won't need to troubleshoot. You're having errors because you aren't following the directions. Just to be blunt. Just rewatch the videos and try again.
2. Sorry, I don't use pycharm or recommend it (for this reason). So I can't guess why it is doing what it's doing. Just use the tools I use. They're free.
@@Codemycom thanks for the reply. I can reassure you I have followed all directions and am just using a different IDE. Not saying it’s an issue with your tutorial but rather may be a common error when people watch this video if they are using an IDE such as PyCharm so just pointing it out in the comments. The main error was the Python terminal couldn’t find Flask for some reason.
@@cricketer1987 Yeah it could be Pycharm...but also...I get hundreds of comments and emails from people SWEARING that they followed the directions...then later saying "oh, whoops, I left out a comma". If it didn't work, it's likely because you missed something. It's no big deal, we all do it.
very useful, thanks
Glad it was helpful!
Love your videos.
Glad you like them!
i like his energy
Thanks!
can you point to where is this database series listed since I could not find sqlite database related coverage in the Flask course on your website.
ruclips.net/p/PLCC34OHNcOtolz2Vd9ZSeSXWc8Bq23yEz
Hi, i get an error when doing db.create_all(). It states that i have to give an app context something like app.app_context()?
have already the solution.
Hi I love your videos!
But I am having a problem... the db file is not creating after the db.creat_all() can you please help me?
@Nezhat Nour >>> db.create_all()
Traceback (most recent call last):
File "", line 1, in
NameError: name 'db' is not defined
This error still pops up after
It would be cool to inform the last commit on starting the tutorial - so we pick up exactly where you are starting from.
It’s showing “ there was an error adding your friend...” How to resolve it?
Got resolved!
I am getting an error(ModuleNotFoundError: No module named 'flask_sqlalchemy') but I have already installed. Can u help me?
Try to use "pip install Flask-SQLAlchemy" in GIT BASH terminal.
Have u done from flask_sqlalchemy import SQLAlchemy
sir when i write "from app import db" i get the error
"ImportError: cannot import name 'SQLALchemy' from 'flask_sqlalchemy'"
pls help me
i google it and i didn't find the solution
Did you do it the same way I did it in the video? Exactly?
Sorry if this is late, but it looks like you imported “SQLALchemy” instead of “SQLAlchemy”
If I made a User model and created it via de Python Interpreter. How can I add a new rows? For example, if you wanted to add a row 'Gender' to your existing database after you did the command db.create_all()?
So helpful!
Thanks! Glad you found it so..
i'm on mac osx and having trouble using "winpty python". is there a mac version of this command or do i have to take extra steps to install the necessary libraries for this command?
leave off the winpty, that's just a windows thing
I am not able to display the information after submitting the form. Can you tell me where I could be wrong? I followed the video step by step but instead I just used more variables than just a name.
No I couldn't guess. Try redoing it exactly as the video shows and see if you can get that to work before trying something differently.
what if I have multiple apps in the Blueprint structure, how can I create a database with its model for each app separately ?
Hi, I wanna know how to make a gallery (flask-html) using images taked from a sql database (sqlite3)
Thanks
can this work with programs such a SQLight Studio?
yes, that's the default db
Great!!!
do you have a video on how to remove a friend from the list?
Maybe not specifically, but many videos on the other playlist of deleting items from a database
I have trouble in loading the data into db, what I get from db is , etc.. rather than the info that I entered into the form...
Weird. What did you do differently than the videos?
@@Codemycom I figured it out. In my case, I created multiple columns in the DB, hence to fetch data from it, i need to specify the column name (record.column1, record.column2), otherwise it will just give me etc which representing the whole row of record
Can you help me with this error? ModuleNotFoundError: No module named 'app'
When I try to set default=datetime.utcnow I get an error saying the equals sign does not belong there.
did you google the error?
@@Codemycom no also I would like to add a subject line to the emails and I couldn't find the solution
Beautiful 💞💞💞
Thanks!
When someone put the details in our subscribe web page, how to store that information in database?
Hey, where can I get code files?
can you help me with my css, i write this on my code when i change background to blue (from the previous tutorial) it changed, but when i want to change it to white in this tutorial, it wont change, and stay at dark blue, even when i deleted the css file it still doesnt change, my background still dark blue :'(
Shift+Reload the page, if that doesn't work restart your browser, if that doesn't work, clear your browser cache
@@Codemycom thankyou, it works now :)
@@Codemycom umm, i got problem again :'( pls help, i use flash messages, so when i want to insert data it will show a flash messages, i can fill my flash messages, but it doesn't show up 😭, i'm still learning so i don't have money to learn from many source :'(
@@felixutomo6365 Don't know man, there's got to be a typo in your code then.
@@Codemycom okk thankyouuu my fav youtuber, i already fix it, anyway i tried ur code, and when i run it, flask doesn't run, it just showed like this:
flask run
(virtual)
without showing any errors or server
Why do you have to create a db using gitbash? Why can't it be written in the code?
That's how it's done
@@Codemycom I'm just think that if DB connection crashes if you just rereun the flask app.py (or whatever) it would create the database. I would have thought the gitbash command to create the database can be directly embedded in the flask file code. Obviously not.
how to connect to existing database(SQL) with SQLALchemy?
I'm having an error when tyring to import db >>> from app import db
C:\Users\user\AppData\Local\Programs\Python\Python310\lib\site-packages\flask_sqlalchemy\__init__.py:851: UserWarning: Neither SQLALCHEMY_DATABASE_URI nor SQLALCHEMY_BINDS is set. Defaulting SQLALCHEMY_DATABASE_URI to "sqlite:///:memory:". Can someone help me pls?
i get "500 internal server error" when i created the db and go the friends page.
You missed something then...try retracing your steps
@@Codemycom i retrace and found one wrong.
But get error, no such table: friends
return render_template("friends.html", friends=friends)
@@ludvignordqvist1552 PLEASE HELP me i have the same error :(
@@ludvignordqvist1552 and i dont know why
Sir i got unresolved reference for SQLAlchemy
how to access db object in sub modules
really usefull video thanks!!
when i hit the "add name" button, nothing happend. Someont know why?
Glad you liked it. nothing happened because you have an error in your code. No one can guess what that error is...likely a typo
@@Codemycom true: i had written "type = "submit"" and not "type="submit"". The blanc between the "=" was the problem
ModuleNotFoundError: No module named 'flask_sqlalchemy' ....
What did you do differently from the video?
@@Codemycom I'm sorry. I installed it correctly. Installing in pycharm worked.
@@neilgriffin9502 Apparently you didn't, or you wouldn't have an error
It won't let me import the db
When I try it runs the server and exits python
What exact error do you get?
@@Codemycom Can't find main method in my project directory
I had to a conditional saying if __name__ = "__main__" app.run
Now it workd
@@MagicByIzzy interesting
Not showing my database
c:\users\medion\desktop\wb env\virtual\lib\site-packages\flask_sqlalchemy\__init__.py:812: UserWarning: Neither SQLALCHEMY_DATABASE_URI nor SQLALCHEMY_BINDS is set. Defaulting SQLALCHEMY_DATABASE_URI to "sqlite:///:memory:".
warnings.warn(
EDIT:never mind i forgot the A in DATABASE
ha, glad you got it sorted out
@@Codemycom Hi there. I have the same error message as Akram, but I am fairly certain that I have spelt everything correctly. Is there any other possible issues?
Thanks!
@@andychang2739 Probably not
@@Codemycom i have the same issue, everything is correctly spelt
What is the best way to add multiple user inputs as far as the db.session.add is concerned in the app.py file?
i.e. db.session.add(this_db_column, that_db_column, this_other_db_column)
Here we go, got it. Hope this helps someone. pastebin.com/Yca8xUih
sir kindly help me i'm getting error:
sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) unable to open database file
(Background on this error at: sqlalche.me/e/13/e3q8)
nice doggy
Thanks
Just wonder, if anyone is able to run on google app engine?
why not?
Where is the Django?
This is a Flask video, not Django
@@Codemycom I understand. I wait Django video.
Please don't delete Bob.
can you create tutorial on simple user management system in flask api something like this -------------------------
I have the following tables:
Table name= group Attributes:
id name
Here simply the group is created.
------------------------------------------------------------------------------
Table name = group permission
Attributes: id group_id Permission_id
Here simply the permission for the group is assigned
-----------------------------------------------------------------------------
Table name =permission
Attributes: id name code name
Here permission is created Table name =user Attributes: id username password
-------------------------------------------------------------------------------
Here the user is created
Table name =user_groups
Attributes: Id User_id Group_id
Here the group for the user is assigned and all the permission inside this group should also be assigned to that user
--------------------------------------------------------------------------------------------------------------------------
Table name =user_permission
Attributes: Id User_id Permission_id
Here the user might get more permission other than the permission assigned from the group.
For example, if the user has only access for reading and writes from it’s defined group then if the admin user wants then he/she can directly assign permission to access a certain menu to the specific user without assigning to the other user of the same group.
I haven't seen anyone on youtube have done this stuff
Is this a school project?
@@Codemycom this is not school project i have been trying this stuff to do for my own but cannot carry out
Thanks a lot for the tutorial. However, I meet sqlalchemy.exe.OperationalError: (sqlite3.OperationalError) no such column when I try the same steps you showed. Could I know what is the potential thing that I missed here? Thanks a lot!
No clue, rewatch the video and try again.
You didn't created the database file or you made a mistake on the 'SQLALCHEMY_DATABSE_URI' line
I get error.. [ no module found MYSQLdb]
How can I solve
follow the instructions in the video exactly