Using Databases With Flask - Python and Flask #8

Поделиться
HTML-код
  • Опубликовано: 1 фев 2025

Комментарии • 140

  • @Codemycom
    @Codemycom  4 года назад

    ▶️ 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

    • @JoshKonoff1
      @JoshKonoff1 4 года назад

      Do you have a Patreon page?

    • @Codemycom
      @Codemycom  4 года назад

      @@JoshKonoff1 No, but you can sign up for a membership at my website Codemy.com

  • @takodamundy4506
    @takodamundy4506 3 года назад +6

    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

  • @df6148
    @df6148 2 года назад +2

    This force is very strong with this one. Indeed a Jedi of his craft. Indeed is he.

  • @faithnjoki5573
    @faithnjoki5573 3 года назад +1

    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

    • @Codemycom
      @Codemycom  3 года назад +1

      You're welcome! Happy New Year!

  • @Flamiooo
    @Flamiooo 4 года назад +2

    I had been waiting for this video for so long, finally

  • @ciyaturgut
    @ciyaturgut 4 года назад

    Man i love your flask videos

  • @kwabenankyi
    @kwabenankyi 2 года назад +1

    very simple and easy to follow tutorial, thank you very much

  • @jean-paullavalley9848
    @jean-paullavalley9848 2 года назад +2

    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)"

    • @jean-paullavalley9848
      @jean-paullavalley9848 2 года назад

      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

  • @TechWithSabri
    @TechWithSabri 4 года назад +2

    Thank you for sharing your knowledge Sir we love you

  • @danielhansen7519
    @danielhansen7519 3 года назад +3

    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?

  • @akramelomrani8728
    @akramelomrani8728 4 года назад

    Finnaly some databases tnx man

  • @tochukwunwokolo2048
    @tochukwunwokolo2048 4 года назад +2

    Hi, thanks for your easy-to-follow videos, could you do a video for searching through a database with Flask?

    • @Codemycom
      @Codemycom  4 года назад +1

      Glad you're enjoying them! I might do something like that in the future...

  • @benjaminodriscoll6605
    @benjaminodriscoll6605 3 года назад

    Explained really clearly, thanks alot!

  • @marlegagaming1274
    @marlegagaming1274 3 года назад +1

    Quite Informative, Any reason why you're not using PyCharm or VSCode, would make life easier with imports etc..,

    • @Codemycom
      @Codemycom  3 года назад +1

      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.

  • @cricketer1987
    @cricketer1987 Год назад

    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.

    • @Codemycom
      @Codemycom  Год назад

      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.

    • @cricketer1987
      @cricketer1987 Год назад

      @@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.

    • @Codemycom
      @Codemycom  Год назад +1

      @@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.

  • @rezaghasemzadeh9440
    @rezaghasemzadeh9440 7 месяцев назад

    very useful, thanks

    • @Codemycom
      @Codemycom  7 месяцев назад

      Glad it was helpful!

  • @eshaangupta4101
    @eshaangupta4101 4 года назад

    Love your videos.

  • @selmamilena2503
    @selmamilena2503 2 года назад

    i like his energy

  • @chotagunnu7489
    @chotagunnu7489 3 года назад

    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.

    • @Codemycom
      @Codemycom  3 года назад

      ruclips.net/p/PLCC34OHNcOtolz2Vd9ZSeSXWc8Bq23yEz

  • @wimvangeyt3866
    @wimvangeyt3866 2 месяца назад

    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()?

  • @ophirn.m7817
    @ophirn.m7817 2 года назад +1

    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?

    • @supersentaimexicano1967
      @supersentaimexicano1967 2 года назад

      @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

  • @kshitijmathur1358
    @kshitijmathur1358 3 года назад

    It would be cool to inform the last commit on starting the tutorial - so we pick up exactly where you are starting from.

  • @pikachubooo4308
    @pikachubooo4308 4 года назад +2

    It’s showing “ there was an error adding your friend...” How to resolve it?

  • @bolatbekminbayev9217
    @bolatbekminbayev9217 4 года назад +1

    I am getting an error(ModuleNotFoundError: No module named 'flask_sqlalchemy') but I have already installed. Can u help me?

    • @vasiliystepanov7423
      @vasiliystepanov7423 4 года назад +1

      Try to use "pip install Flask-SQLAlchemy" in GIT BASH terminal.

    • @justash123
      @justash123 2 года назад

      Have u done from flask_sqlalchemy import SQLAlchemy

  • @fouadlhort5439
    @fouadlhort5439 4 года назад +1

    sir when i write "from app import db" i get the error
    "ImportError: cannot import name 'SQLALchemy' from 'flask_sqlalchemy'"
    pls help me

    • @fouadlhort5439
      @fouadlhort5439 4 года назад

      i google it and i didn't find the solution

    • @Codemycom
      @Codemycom  4 года назад

      Did you do it the same way I did it in the video? Exactly?

    • @devan8166
      @devan8166 4 года назад

      Sorry if this is late, but it looks like you imported “SQLALchemy” instead of “SQLAlchemy”

  • @antoinekikkers9022
    @antoinekikkers9022 2 года назад

    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()?

  • @manasavallampalli
    @manasavallampalli 4 года назад

    So helpful!

    • @Codemycom
      @Codemycom  4 года назад

      Thanks! Glad you found it so..

  • @dktitanx2773
    @dktitanx2773 3 года назад

    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?

    • @Codemycom
      @Codemycom  3 года назад +1

      leave off the winpty, that's just a windows thing

  • @ayushagarwal4958
    @ayushagarwal4958 4 года назад

    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
      @Codemycom  4 года назад

      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.

  • @MohamedAshraf-zs6nv
    @MohamedAshraf-zs6nv 4 года назад

    what if I have multiple apps in the Blueprint structure, how can I create a database with its model for each app separately ?

  • @MarkTw20
    @MarkTw20 4 года назад

    Hi, I wanna know how to make a gallery (flask-html) using images taked from a sql database (sqlite3)
    Thanks

  • @matthewbraymer1136
    @matthewbraymer1136 2 года назад

    can this work with programs such a SQLight Studio?

    • @Codemycom
      @Codemycom  2 года назад

      yes, that's the default db

  • @AKhan-3
    @AKhan-3 3 года назад

    Great!!!

  • @davidbeiler6364
    @davidbeiler6364 2 года назад

    do you have a video on how to remove a friend from the list?

    • @Codemycom
      @Codemycom  2 года назад

      Maybe not specifically, but many videos on the other playlist of deleting items from a database

  • @stormschaser
    @stormschaser 4 года назад

    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...

    • @Codemycom
      @Codemycom  4 года назад

      Weird. What did you do differently than the videos?

    • @stormschaser
      @stormschaser 4 года назад

      @@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

  • @victorcirillo1016
    @victorcirillo1016 2 года назад

    Can you help me with this error? ModuleNotFoundError: No module named 'app'

  • @MagicByIzzy
    @MagicByIzzy 4 года назад

    When I try to set default=datetime.utcnow I get an error saying the equals sign does not belong there.

    • @Codemycom
      @Codemycom  4 года назад

      did you google the error?

    • @MagicByIzzy
      @MagicByIzzy 4 года назад

      @@Codemycom no also I would like to add a subject line to the emails and I couldn't find the solution

  • @mbonuchinedu2420
    @mbonuchinedu2420 4 года назад

    Beautiful 💞💞💞

  • @parthdutta8758
    @parthdutta8758 3 года назад

    When someone put the details in our subscribe web page, how to store that information in database?

  • @Onecool0
    @Onecool0 3 года назад +1

    Hey, where can I get code files?

  • @felixutomo6365
    @felixutomo6365 4 года назад

    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
      @Codemycom  4 года назад +1

      Shift+Reload the page, if that doesn't work restart your browser, if that doesn't work, clear your browser cache

    • @felixutomo6365
      @felixutomo6365 4 года назад

      @@Codemycom thankyou, it works now :)

    • @felixutomo6365
      @felixutomo6365 4 года назад

      @@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
      @Codemycom  4 года назад

      @@felixutomo6365 Don't know man, there's got to be a typo in your code then.

    • @felixutomo6365
      @felixutomo6365 4 года назад

      @@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

  • @rdubitsk
    @rdubitsk 4 года назад

    Why do you have to create a db using gitbash? Why can't it be written in the code?

    • @Codemycom
      @Codemycom  4 года назад

      That's how it's done

    • @rdubitsk
      @rdubitsk 4 года назад

      @@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.

  • @narendrareddy8420
    @narendrareddy8420 3 года назад

    how to connect to existing database(SQL) with SQLALchemy?

  • @supersentaimexicano1967
    @supersentaimexicano1967 2 года назад

    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?

  • @ludvignordqvist1552
    @ludvignordqvist1552 4 года назад

    i get "500 internal server error" when i created the db and go the friends page.

    • @Codemycom
      @Codemycom  4 года назад

      You missed something then...try retracing your steps

    • @ludvignordqvist1552
      @ludvignordqvist1552 4 года назад

      @@Codemycom i retrace and found one wrong.
      But get error, no such table: friends
      return render_template("friends.html", friends=friends)

    • @programminginmymind2446
      @programminginmymind2446 4 года назад

      @@ludvignordqvist1552 PLEASE HELP me i have the same error :(

    • @programminginmymind2446
      @programminginmymind2446 4 года назад

      @@ludvignordqvist1552 and i dont know why

  • @tatividumaamey5828
    @tatividumaamey5828 2 года назад

    Sir i got unresolved reference for SQLAlchemy

  • @alfredsyriac
    @alfredsyriac 2 года назад

    how to access db object in sub modules

  • @MrSharkrat
    @MrSharkrat 3 года назад

    really usefull video thanks!!
    when i hit the "add name" button, nothing happend. Someont know why?

    • @Codemycom
      @Codemycom  3 года назад

      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

    • @MrSharkrat
      @MrSharkrat 3 года назад

      @@Codemycom true: i had written "type = "submit"" and not "type="submit"". The blanc between the "=" was the problem

  • @neilgriffin9502
    @neilgriffin9502 2 года назад

    ModuleNotFoundError: No module named 'flask_sqlalchemy' ....

    • @Codemycom
      @Codemycom  2 года назад

      What did you do differently from the video?

    • @neilgriffin9502
      @neilgriffin9502 2 года назад

      @@Codemycom I'm sorry. I installed it correctly. Installing in pycharm worked.

    • @Codemycom
      @Codemycom  2 года назад

      @@neilgriffin9502 Apparently you didn't, or you wouldn't have an error

  • @MagicByIzzy
    @MagicByIzzy 4 года назад

    It won't let me import the db
    When I try it runs the server and exits python

    • @Codemycom
      @Codemycom  4 года назад

      What exact error do you get?

    • @MagicByIzzy
      @MagicByIzzy 4 года назад

      @@Codemycom Can't find main method in my project directory

    • @MagicByIzzy
      @MagicByIzzy 4 года назад

      I had to a conditional saying if __name__ = "__main__" app.run

    • @MagicByIzzy
      @MagicByIzzy 4 года назад

      Now it workd

    • @Codemycom
      @Codemycom  4 года назад

      @@MagicByIzzy interesting

  • @akramelomrani8728
    @akramelomrani8728 4 года назад

    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
      @Codemycom  4 года назад +1

      ha, glad you got it sorted out

    • @andychang2739
      @andychang2739 4 года назад

      @@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!

    • @Codemycom
      @Codemycom  4 года назад

      @@andychang2739 Probably not

    • @tonymonta3
      @tonymonta3 3 года назад

      @@Codemycom i have the same issue, everything is correctly spelt

  • @misterbristles
    @misterbristles 4 года назад

    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)

    • @misterbristles
      @misterbristles 4 года назад

      Here we go, got it. Hope this helps someone. pastebin.com/Yca8xUih

  • @mahadevkalshetty4943
    @mahadevkalshetty4943 4 года назад

    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)

  • @m-jay356
    @m-jay356 3 года назад

    nice doggy

  • @hans.k3534
    @hans.k3534 3 года назад

    Just wonder, if anyone is able to run on google app engine?

  • @gamerstrim
    @gamerstrim 4 года назад

    Where is the Django?

    • @Codemycom
      @Codemycom  4 года назад

      This is a Flask video, not Django

    • @gamerstrim
      @gamerstrim 4 года назад

      @@Codemycom I understand. I wait Django video.

  • @teclote
    @teclote Год назад

    Please don't delete Bob.

  • @sudeeptimsina4600
    @sudeeptimsina4600 4 года назад

    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

    • @Codemycom
      @Codemycom  4 года назад

      Is this a school project?

    • @sudeeptimsina4600
      @sudeeptimsina4600 4 года назад

      @@Codemycom this is not school project i have been trying this stuff to do for my own but cannot carry out

  • @ruiyang9235
    @ruiyang9235 3 года назад

    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!

    • @Codemycom
      @Codemycom  3 года назад

      No clue, rewatch the video and try again.

    • @zeyx6534
      @zeyx6534 2 года назад

      You didn't created the database file or you made a mistake on the 'SQLALCHEMY_DATABSE_URI' line

  • @raselahmed2221
    @raselahmed2221 4 года назад

    I get error.. [ no module found MYSQLdb]
    How can I solve

    • @Codemycom
      @Codemycom  4 года назад

      follow the instructions in the video exactly