Python Flask Tutorial: Full-Featured Web App Part 9 - Pagination

แชร์
ฝัง
  • เผยแพร่เมื่อ 20 ก.ย. 2024

ความคิดเห็น • 291

  • @MikeJans
    @MikeJans 6 ปีที่แล้ว +113

    Im not yet finnished but absolutely amazing tutorials!!!! probably the best on youtube!

    • @coreyms
      @coreyms  6 ปีที่แล้ว +4

      Thanks!

    • @zainbaloch5541
      @zainbaloch5541 5 ปีที่แล้ว

      same here, and it definitely is the best one so far I suppose!

    • @omerahmaad
      @omerahmaad 4 ปีที่แล้ว

      I can't agree more Corey is awesome

    • @dantesparda7777
      @dantesparda7777 4 ปีที่แล้ว

      True!

    • @codewithmorris6492
      @codewithmorris6492 3 ปีที่แล้ว

      Just pure awesome!

  • @iansharp1171
    @iansharp1171 4 ปีที่แล้ว +26

    Utterly outstanding! I've been programming for 40 years and I've never come across tutorials as good as yours before!

    • @coreyms
      @coreyms  4 ปีที่แล้ว +1

      Thanks!

  • @Cytzix
    @Cytzix 5 ปีที่แล้ว +77

    It's funny to see that part 1 has 144k views yet part 9 only 12k. I assume that some dudes have given up their flask path despite this series is so easy to follow. I myself started this tutorial late October with part 1 and hopefully will be finishing the last part by end of December. In 2019 I plan to create my own web app with the knowledge I acquired. Thanks Corey for doing such great job!

    • @lightninginmyhands4878
      @lightninginmyhands4878 5 ปีที่แล้ว +6

      And it goes to show.. doesn't matter in this case that its free (and the DEFINITIVE guide to Flask in 2019)! People must summon their discipline

    • @fazalali2894
      @fazalali2894 4 ปีที่แล้ว +5

      @@lightninginmyhands4878 I'm sure there's people who just gave up after the first video but it's not just discipline. The intro serves to introduce the topic so there's probably a lot of people that just want to know what flask is... or people who already use different frameworks and wanted to check out flask...etc

    • @user-sg7yd5il3z
      @user-sg7yd5il3z 3 ปีที่แล้ว +4

      @@fazalali2894 Yeah or could be like me and doesn't need every video for their project. This is my 2nd go at the tutorials but the first time all I needed was the first 3 tutorials to search and display some static information. This time around my goal is to learn how to design a fully featured website.
      It's still amusing to see how the views/likes go down with each video. But there's multiple reasons for this, not just lack of discipline.

    • @liorschifrin
      @liorschifrin 9 หลายเดือนก่อน

      Did you end up making your own site?

    • @AndreiSokolov-k7j
      @AndreiSokolov-k7j 4 หลายเดือนก่อน

      now on first video 1 million views and on 9th video 120k views... same ol same ol

  • @1cannon3
    @1cannon3 5 ปีที่แล้ว +138

    ⌨️ 1:30 Introduction to flask SQLAlchemy paginate method
    ⌨️ 1:45 Changing our db query in our /home route from .all( ) to .paginate( )
    ⌨️ 2:00 Using the command line to investigate the .paginate( ) method
    ⌨️ 3:08 The “Pagination” object and its attributes
    - 3:15 Using the dir( ) function, i.e. dir(post)
    - 3:32 Investigating the “page” object
    - 3:43 Investigating the “per_page” attribute
    - 3:45 posts.per_page
    - 4:30 the last 5 blog posts are on second page because default is set to 20 items per page
    - 4:36 How to access second page of items
    - 4:50 posts = Post.query.paginate(page=2)
    - 5:14 changing the number of posts per page
    - 4:50 posts = Post.query.paginate(per_page=5) #five per page
    ⌨️ 6:30 returning to app/routes.py to integrate pagination
    - 6:55 Setting the post per page = 5
    - 6:55 Post.query.paginate(per_page=5)
    - 7:20 Grabbing the page we want a opposed to the default, page 1
    - ^ 6:55 We obtain this from a query parameter in the url, requests library
    - 6:55 Post.query.paginate(per_page=5)
    - 8:05 Updating home.html template to reflect changes
    - 8:52 Currently links to other pages are not wired up
    - 8:56 manually pass query parameter to test other pages
    - 9:08 …?page=2
    ⌨️ 9:34 Update template to display links/buttons to next pages
    - 6:55 Setting the post per page = 5
    - 10:05 Using the command line to investigate how to do this
    - 10:54 Intro to the method .iter_pages( )
    - 11:22 How modern webpages display the page sequence to user
    - 11:50 Passing arguments to .iter_pages( ) to limit/modify amount of pages displayed to user
    - 12:10 Updating home.html template to display all page links via button
    - 16:44 Styling with bootstrap to show the current page the user is on
    ⌨️ 19:13 Sorting posts by date created
    - 19:44 This done by reordering in our query
    - 20:04 This will be achieved via routes.py
    - 20:10 VERY SIMPLE! just add .order_by(Post.date_posted.desc()) to the bd query
    - 20:36 Post.query.orer_by(Post.date_posted.desc()).paginate(page=page, per_page=5)
    ⌨️ 21:19 Lastly, creating route for when you click on a specific user
    - 21:42 Corey creates the new route
    - 22:08 The new route is /user/
    - 22:48 Creating the db query within this new route (we need to filter by username now)
    - 24:39 Creating a new template for a specific users page (user_posts.html)
    - 27:30 We need to update the href for home.html and post.html
    - 28:05 Updating the pagination links on user_posts.html

    • @KaelusVonSestiaf
      @KaelusVonSestiaf 4 ปีที่แล้ว +6

      these comments need to be pinned, tbh

    • @sogbeydaniel8074
      @sogbeydaniel8074 4 ปีที่แล้ว

      😂😂😂😂 amazing ✊🏻✊🏻✊🏻👍👍👍👍👌👌👌👌🙏🙏🙏🙏

    • @jakobfredriksson2272
      @jakobfredriksson2272 4 ปีที่แล้ว

      Haha! Indeed! Yes... I'm more or less just coding along by this point and will rewatch this amazing course again with a thick note block afterwards =)

    • @eflsteve
      @eflsteve 3 ปีที่แล้ว

      @Jacob you're a legend mate, did you do timestamps on the other vids that you've not added this? Trying to consolidate this information before I forget it all (again!) and they're pretty helpful!

    • @eflsteve
      @eflsteve 3 ปีที่แล้ว +1

      Here's the cleaned up Markdown for this folks:
      - [1:30](th-cam.com/video/PSWf2TjTGNY/w-d-xo.html) Introduction to flask SQLAlchemy paginate method
      - [1:45](th-cam.com/video/PSWf2TjTGNY/w-d-xo.html) Changing our db query in our /home route from .all( ) to .paginate( )
      - [2:00](th-cam.com/video/PSWf2TjTGNY/w-d-xo.html) Using the command line to investigate the .paginate( ) method
      - [3:08](th-cam.com/video/PSWf2TjTGNY/w-d-xo.html) The “Pagination” object and its attributes
      - [3:15](th-cam.com/video/PSWf2TjTGNY/w-d-xo.html) Using the dir( ) function, i.e. dir(post)
      - [3:32](th-cam.com/video/PSWf2TjTGNY/w-d-xo.html) Investigating the “page” object
      - [3:43](th-cam.com/video/PSWf2TjTGNY/w-d-xo.html) Investigating the “per\_page” attribute
      - [3:45](th-cam.com/video/PSWf2TjTGNY/w-d-xo.html) posts.per\_page
      - [4:30](th-cam.com/video/PSWf2TjTGNY/w-d-xo.html) the last 5 blog posts are on second page because default is set to 20 items per page
      - [4:36](th-cam.com/video/PSWf2TjTGNY/w-d-xo.html) How to access second page of items
      - [4:50](th-cam.com/video/PSWf2TjTGNY/w-d-xo.html) posts = Post.query.paginate(page=2)
      - [5:14](th-cam.com/video/PSWf2TjTGNY/w-d-xo.html) changing the number of posts per page
      - [4:50](th-cam.com/video/PSWf2TjTGNY/w-d-xo.html) posts = Post.query.paginate(per\_page=5) [#five](th-cam.com/users/hashtagfive) per page
      - [6:30](th-cam.com/video/PSWf2TjTGNY/w-d-xo.html) returning to app/[routes.py](th-cam.com/users/redirect?q=http%3A%2F%2Froutes.py%2F&redir_token=QUFFLUhqbmlPaWdka3k1R0ZQUzFCU3VyQ3Z3NGlROEtGZ3xBQ3Jtc0tsNnlwS0dLN3Q1SzBuU3loanV4cHpwUU9yUmx2NndTUnRWb2xLOW84eW9pc1BJVElERnZneXNrc0xKRFVWRlM3ZEdZX0FfOGtEMlZTdHNmRWt6TVNiTmQ4cHhvd3MxSDRfWlB0cDVRUVI3cTBOZWhhSQ%3D%3D&stzid=Ugw3RnXbD_VfEQi2vTJ4AaABAg&event=comments) to integrate pagination
      - [6:55](th-cam.com/video/PSWf2TjTGNY/w-d-xo.html) Setting the post per page = 5
      - [6:55](th-cam.com/video/PSWf2TjTGNY/w-d-xo.html) Post.query.paginate(per\_page=5)
      - [7:20](th-cam.com/video/PSWf2TjTGNY/w-d-xo.html) Grabbing the page we want a opposed to the default, page 1
      - [6:55](th-cam.com/video/PSWf2TjTGNY/w-d-xo.html) We obtain this from a query parameter in the url, requests library
      - [6:55](th-cam.com/video/PSWf2TjTGNY/w-d-xo.html) Post.query.paginate(per\_page=5)
      - [8:05](th-cam.com/video/PSWf2TjTGNY/w-d-xo.html) Updating home.html template to reflect changes
      - [8:52](th-cam.com/video/PSWf2TjTGNY/w-d-xo.html) Currently links to other pages are not wired up
      - [8:56](th-cam.com/video/PSWf2TjTGNY/w-d-xo.html) manually pass query parameter to test other pages
      - [9:08](th-cam.com/video/PSWf2TjTGNY/w-d-xo.html) …?page=2
      - [9:34](th-cam.com/video/PSWf2TjTGNY/w-d-xo.html) Update template to display links/buttons to next pages
      - [6:55](th-cam.com/video/PSWf2TjTGNY/w-d-xo.html) Setting the post per page = 5
      - [10:05](th-cam.com/video/PSWf2TjTGNY/w-d-xo.html) Using the command line to investigate how to do this
      - [10:54](th-cam.com/video/PSWf2TjTGNY/w-d-xo.html) Intro to the method .iter\_pages( )
      - [11:22](th-cam.com/video/PSWf2TjTGNY/w-d-xo.html) How modern webpages display the page sequence to user
      - [11:50](th-cam.com/video/PSWf2TjTGNY/w-d-xo.html) Passing arguments to .iter\_pages( ) to limit/modify amount of pages displayed to user
      - [12:10](th-cam.com/video/PSWf2TjTGNY/w-d-xo.html) Updating home.html template to display all page links via button
      - [16:44](th-cam.com/video/PSWf2TjTGNY/w-d-xo.html) Styling with bootstrap to show the current page the user is on
      - [19:13](th-cam.com/video/PSWf2TjTGNY/w-d-xo.html) Sorting posts by date created
      - [19:44](th-cam.com/video/PSWf2TjTGNY/w-d-xo.html) This done by reordering in our query
      - [20:04](th-cam.com/video/PSWf2TjTGNY/w-d-xo.html) This will be achieved via [routes.py](th-cam.com/users/redirect?q=http%3A%2F%2Froutes.py%2F&redir_token=QUFFLUhqbUtvbG44eTRSTjBZaHhYcnNhS2xwaWVoOTU5Z3xBQ3Jtc0tuVDVsRGg2OXlibnEwUkJudFUxV1UxdWRRNjluY2JRMU5lc2phbkJ4d0pjOURLZENtMnk5ZWpGRHh3QXo0bmFyOVZrREt4T3JfZEdiNG54ajhZX0RRenI4aVVYb2s0T1BZV2EyQy1ic05iaGNRWTdKOA%3D%3D&stzid=Ugw3RnXbD_VfEQi2vTJ4AaABAg&event=comments)
      - [20:10](th-cam.com/video/PSWf2TjTGNY/w-d-xo.html) VERY SIMPLE! just add .order\_by(Post.date\_posted.desc()) to the bd query
      - [20:36](th-cam.com/video/PSWf2TjTGNY/w-d-xo.html) Post.query.orer\_by(Post.date\_posted.desc()).paginate(page=page, per\_page=5)
      - [21:19](th-cam.com/video/PSWf2TjTGNY/w-d-xo.html) Lastly, creating route for when you click on a specific user
      - [21:42](th-cam.com/video/PSWf2TjTGNY/w-d-xo.html) Corey creates the new route
      - [22:08](th-cam.com/video/PSWf2TjTGNY/w-d-xo.html) The new route is /user/
      - [22:48](th-cam.com/video/PSWf2TjTGNY/w-d-xo.html) Creating the db query within this new route (we need to filter by username now)
      - [24:39](th-cam.com/video/PSWf2TjTGNY/w-d-xo.html) Creating a new template for a specific users page (user\_posts.html)
      - [27:30](th-cam.com/video/PSWf2TjTGNY/w-d-xo.html) We need to update the href for home.html and post.html
      - [28:05](th-cam.com/video/PSWf2TjTGNY/w-d-xo.html) Updating the pagination links on user\_posts.html

  • @guiics163
    @guiics163 3 ปีที่แล้ว +18

    In case anyone wants to add the json file into the db, i just figure it out a way of doing it:
    run python
    from flaskblog import db
    from flaskblog.models import Post
    import json
    file = open(''. 'r')
    data = json.load(file)
    for x in data:
    post = Post(title = x.get('title'), content = x.get('content'), user_id = x.get('user_id'))
    db.session.add(post)
    db.session.add(commit)

    • @bjmaynard01
      @bjmaynard01 2 ปีที่แล้ว

      Thank you, I've been trying to find a solution on my own for a few days now.

    • @vinaf4494
      @vinaf4494 2 ปีที่แล้ว +1

      Thanks! Help a lot!

    • @ianmillard1604
      @ianmillard1604 ปีที่แล้ว

      absolute champion!

    • @sameyworkspace
      @sameyworkspace ปีที่แล้ว

      Thanks alot

    • @ben866240
      @ben866240 5 หลายเดือนก่อน +2

      Big thanks !
      Changed it a bit and this works for me.
      ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
      run python
      from flaskblog import app, db
      from flaskblog.models import Post
      import json
      file = open('')
      data = json.load(file)
      app.app_context().push()
      for x in data:
      post = Post(title = x.get('title'), content = x.get('content'), user_id = x.get('user_id'))
      db.session.add(post)
      db.session.commit()

  • @ritheshjarvis4177
    @ritheshjarvis4177 4 ปีที่แล้ว +10

    Best Flask Resource over Internet.. Thank u Corey.. You are the Best..

  • @peti826
    @peti826 4 ปีที่แล้ว +3

    I don't know if this is intentional, but the amount of content you show is just brilliant in terms of learning how to use Flask, at least for me.
    Somehow you manage to make it look so easy to add these features to the code that in each of your videos by the time you get to the middle of the video and explain what the next thing you are going to do is I always get a feeling that I am going to be able to do it without help, and most of the time I succeed in it. Like making the pages look better by showing only 5 of them at once, I had no idea if it would work what I did but it was exactly the same what you did later...
    Thank you for the effort you put in your work, really outstanding.

  • @andygordon6880
    @andygordon6880 5 หลายเดือนก่อน

    This series is incredibly well crafted, easy to follow with great detail. The app looks great and lots of tips for further research. Pure excellence, thank you!

  • @StrangeIndeed
    @StrangeIndeed 4 ปีที่แล้ว +1

    You almost never make mistakes. I do at least 2 per video in the series, and it takes be on average 15 minutes to fix the error. But I learn a lot by doing that - it makes me actually think a lot more about what I've typed.
    And thanks for the tutorial. You are the best c:

  • @TheMayank011
    @TheMayank011 ปีที่แล้ว +1

    This is just beautiful !! No other words came to my mind. Thanks for such a detailed explanation.

  • @pawekoaczynski4505
    @pawekoaczynski4505 3 ปีที่แล้ว +6

    24:19 if you don't want to use backslashes to separate long lines like this one, you can wrap the expression in parenthesis.
    So instead of this:
    posts = Post\
    .query\
    .filter_by(author=user)
    You have this:
    posts = (Post
    .query
    .filter_by(author=user))

  • @dragon_warrior_
    @dragon_warrior_ 3 ปีที่แล้ว

    Hands Down to the best flask tutorial available on the internet still stands strong in Feb 2021.....I literally learned so much from these videos thanks Corey

  • @FactDesk
    @FactDesk 4 ปีที่แล้ว +4

    thank you so much , im impressed and interested to do more things in programming after your series of tutorial

  • @ΝΙΚΟΣΚΑΜΠΟΥΡΙΔΗΣ-π2θ
    @ΝΙΚΟΣΚΑΜΠΟΥΡΙΔΗΣ-π2θ 3 ปีที่แล้ว +2

    If you have problem of how you can pass the data from the json file here is the answer:
    import json
    from flaskproject.models import Post
    from flaskproject import db
    with open('posts.json', 'r') as f:
    posts_dict = json.load(f)

    for post in posts_dict:
    post = Post(title=post['title'], content=post['content'], user_id=post['user_id'])
    db.session.add(post)
    db.session.commit()

  • @joescaos
    @joescaos 3 ปีที่แล้ว +2

    Amazing Flask course, I've learned so much, Thanks a lot!

  • @phucthaifg
    @phucthaifg 4 ปีที่แล้ว +2

    What a great effort to make these amazing tutorials. I will try to get all of the points you gave. Thank you so much!

  • @Pixelaze
    @Pixelaze 2 ปีที่แล้ว +1

    Thank you for showing me the means to create my own App.

  • @hill2750
    @hill2750 4 ปีที่แล้ว +1

    Thank you sooooo much for putting the code for this series on github! :)

  • @ivanyakushchenko6915
    @ivanyakushchenko6915 6 ปีที่แล้ว +5

    Great lesson! You explain it so easy and interesting! Thanks a lot!

  • @gwanghyeongim768
    @gwanghyeongim768 4 ปีที่แล้ว +4

    For those who want your local date(or time) to be shown(suppose you're not in UK), use default=datetime.now in models.py for date_posted field in Post class, instead of datetime.utcnow

    • @fazalali2894
      @fazalali2894 4 ปีที่แล้ว

      Yes that's valid as far code goes but it is standard practice to use UTC time with your database. There's multiple reasons for it and I implore you to search for them online but one big one is that your users may not be in the same time zone as you. For me, I store the time in UTC and if I do need to show the date to the client I use java script to handle the conversion.

  • @Jirkas151CZ
    @Jirkas151CZ 3 ปีที่แล้ว

    This tutorial series is amazing! I really appreciate it! I love when people can use own knowledge and programming skills for creating shortcuts in many boring repetitive tasks, like Corey did with the automated import of his blog articles. (look at the timestamps of post creations :D)

  • @thenerdyanarchist2203
    @thenerdyanarchist2203 5 ปีที่แล้ว +11

    lol @ "These Beers Will Improve Your Programming!"
    That's an article I need to read...

  • @hallvardlundehervig5508
    @hallvardlundehervig5508 3 ปีที่แล้ว +1

    Thank you. I learn more from you than in my university courses

  • @mahdinouroozi6346
    @mahdinouroozi6346 3 ปีที่แล้ว

    Thank you Mr.Schafer, your videos taught me a lot of new things

  • @Unholyknightzz
    @Unholyknightzz 5 ปีที่แล้ว +3

    Awesome tutorial, i can do pagination easy by just follow what u did !

  • @maroskukan8387
    @maroskukan8387 3 ปีที่แล้ว +11

    If anyone is looking for an easy way how to add those 25 posts Corey mentioned without spending lot of time clicking around in the app itself. You can use Python interactive shell
    from flaskblog import db
    from flaskblog.models import User, Post
    posts = [{"title": "My Updated Post", "content": "My first updated post!

    This is exciting!", "user_id": 1}, {"title": "A Second Post",........]
    for post in posts:
    item = Post(title=post['title'], content=post['content'], user_id=post['user_id'])
    db.session.add(item)
    db.session.commit()
    print("Added " + str(post['title']))
    Afterwards your site.db file will be populated from values from the list of posts.

    • @nootyfx2718
      @nootyfx2718 ปีที่แล้ว

      BRABO!

    • @MykhailoRogozhyn
      @MykhailoRogozhyn ปีที่แล้ว

      Thank you very much for help. I didn't figure out how to do it myself.

    • @kamikaze9271
      @kamikaze9271 ปีที่แล้ว

      Very useful. Thanks. A bit tedious to do that in terminal perhaps because I'm not used to the using for loops in the terminal. Still less tedious than doing it manually

  • @phillwheadon5940
    @phillwheadon5940 2 ปีที่แล้ว

    This is really good. Thank you so much. Great rhythm, fluidity and great precision. So logical. Although I am feeling a bit more empowered to make the app I need for a knowledge database I realise that I really do need to learn Python properly. It is the same with PHP RAD systems and Ruby on Rails, that even as you learn the framework it is only when you fully understand the underlying fabric that you can make it do what you want. This is the best framework introduction I have experienced though and because it is so well put together I will want to follow the Python tutorials you refer to. Good luck in life and thanks for contributing to the lives of others in this way.

  • @irmscher9
    @irmscher9 5 ปีที่แล้ว +3

    Exactly what I was looking for. Thank you!

  • @AymenLagha
    @AymenLagha 5 ปีที่แล้ว +14

    can we add a feature that does a "see more " for long posts ?
    great content btw

    • @joeya6635
      @joeya6635 3 ปีที่แล้ว

      Just render the post as a substring, then see more renders the whole string, using javascript

  • @enduringpromise
    @enduringpromise 5 ปีที่แล้ว +3

    Exactly what I was looking for.

  • @untildawn5714
    @untildawn5714 5 ปีที่แล้ว +2

    Your the best mate! Thank for all videos!!! Good job so far

  • @rinkujain1245
    @rinkujain1245 3 ปีที่แล้ว +1

    Probably the only tutorial comparable to the Flask Mega Tutorial!

  • @KkintasS
    @KkintasS 6 ปีที่แล้ว +2

    Excellent tutorials. I'm really enjoying them...

  • @zahrayarmand1652
    @zahrayarmand1652 5 ปีที่แล้ว +1

    you are really a good teacher. I learned a lot from you. Thank you so much for these videos. awesome!

  • @freddanq3705
    @freddanq3705 4 ปีที่แล้ว +3

    Great tutorials...Wish a placeholder can be added to the forms

    • @jerrycrews3127
      @jerrycrews3127 4 ปีที่แล้ว +1

      title = StringField('Title', validators=[DataRequired()], render_kw={"placeholder": "title"})

  • @enginerol
    @enginerol 4 ปีที่แล้ว +2

    If anyone wanted to add next and previous page links to the pagination here is the code:
    {% if posts.has_prev %}
    «
    {% endif %}
    {% for page_num in posts.iter_pages(left_edge=1, right_edge=1, left_current=1, right_current=2) %}
    {% if page_num %}
    {% if posts.page == page_num %}
    {{ page_num }}
    {% else %}
    {{ page_num }}
    {% endif %}
    {% else %}
    ...
    {% endif %}
    {% if posts.has_next %}
    »
    {% endif %}

  • @dylankendrick27
    @dylankendrick27 4 ปีที่แล้ว +1

    for i in dir(data):
    ----print(i)
    gives you a clean list of commands :)

  • @not_amanullah
    @not_amanullah 6 หลายเดือนก่อน

    This flask series is helpful

  • @luiggitello8546
    @luiggitello8546 5 ปีที่แล้ว +9

    This might be a silly question but how do I add the JSON to the data base? Or should I work either with the JSON or the db.posts?

    • @yzraeloa
      @yzraeloa 4 ปีที่แล้ว +9

      # This worked for me:
      # In a python instance paste the JSON to a variable (mine is instr) and use this
      # script
      from flaskblog.models import User, Post
      from flaskblog import db
      # Paste JSON here
      # instr =
      for post in instr:
      author = User.query.filter_by(id=post['user_id']).first()
      Post(title=post['title'], content=post['content'], author=author)
      p = Post(title=post['title'], content=post['content'], author=author)
      db.session.add(p)

      db.session.commit()
      # Hope this helps

    • @riccardopolimeno539
      @riccardopolimeno539 4 ปีที่แล้ว

      @@yzraeloa Thank you

    • @yashararafat8877
      @yashararafat8877 4 ปีที่แล้ว

      @@yzraeloa Thanks a lot Jonathan... This really helped....

  • @experimentalhypothesis1137
    @experimentalhypothesis1137 4 ปีที่แล้ว +2

    whenever i see corey's name, i automatically click like button

  • @yalgret
    @yalgret 4 ปีที่แล้ว +1

    another quality installment

  • @RandomShowerThoughts
    @RandomShowerThoughts 6 ปีที่แล้ว +2

    why does this not have a million views?

  • @remixowlz
    @remixowlz 4 ปีที่แล้ว +2

    After watching your videos/ tutorials, I realized College is a waste of my money lol. You're amazing!

  • @백영래-u3x
    @백영래-u3x 5 ปีที่แล้ว +2

    Thank you for the tutorials!

  • @AbhishekNigam
    @AbhishekNigam 6 ปีที่แล้ว +2

    Thanks a ton for these videos!!!

  • @mojostrowinsky5235
    @mojostrowinsky5235 4 ปีที่แล้ว +1

    Amazing tutorial. Thank you so much

  • @abdelrhmanelbershawi274
    @abdelrhmanelbershawi274 4 ปีที่แล้ว +1

    Amazing Amazing Amazing Amazing tutorials Everrrr

  • @Tuddy93
    @Tuddy93 4 ปีที่แล้ว +1

    Very helpful. Keep it up!

  • @shakthiprarthanav5070
    @shakthiprarthanav5070 3 ปีที่แล้ว

    Absoutely amazing!Thank you so much for this tutorial!

  • @m12652
    @m12652 3 ปีที่แล้ว

    Brilliant! Thanks again.... just a thought: If post IDs are auto-incremented and the primary key, it should be less overhead to order by the ID desc.

  • @rizalvijay4727
    @rizalvijay4727 5 ปีที่แล้ว +2

    best tutorial....i love it!!!

  • @Rec1337
    @Rec1337 2 ปีที่แล้ว

    love your tutorials, learned a lot, thanks dude!

  • @andrewparmar
    @andrewparmar 6 ปีที่แล้ว +1

    To quickly add the posts Corey's is using (see link in description above) you can use the following in a python console opened from your project root directory. Just make sure you have one user created.
    from flaskblog.models import Post
    from flaskblog import db
    posts =

  • @alexkalopsia
    @alexkalopsia 4 ปีที่แล้ว

    Such an incredible course, thank you

  • @luuvinhtuong4490
    @luuvinhtuong4490 5 ปีที่แล้ว +1

    why amazing tutorial have over 14k views but only have 448 like? please like it as a way to express gratitude to the author. Thanks viewers

  • @markusvalentini438
    @markusvalentini438 5 ปีที่แล้ว +40

    22:25 write .

  • @ErickG
    @ErickG 5 ปีที่แล้ว +1

    What do you think would be a good way to study this material to really understand what I've "created"? I've just been looking at the code side-by-side in my text editor with the web app and trying to sort of reverse engineer what's been created. Is that a good way to go about really making this stick?
    Would I be better off trying to recreate the basic parts on a smaller scale and then building up from there? Maybe a bit of what I've said above as well? I feel like I'm about to answer my own question. I think I'll do a bit of both. hmm

  • @borisurkan2223
    @borisurkan2223 6 ปีที่แล้ว

    Great! I love all your tutorials and I'm looking forward to Django tutorial. Thank you!

  • @haroldodiasmagalhaes33
    @haroldodiasmagalhaes33 3 ปีที่แล้ว

    Helo! This helped me a lot, thank you very much. Sorry for my English, Google translator!

  • @jeremiahokai9889
    @jeremiahokai9889 4 ปีที่แล้ว +1

    You doing the Lords work. God bless you!!!

  • @kashibrown9989
    @kashibrown9989 2 ปีที่แล้ว

    Thank you corey...really appreciate you

  • @guylhermef1219
    @guylhermef1219 2 ปีที่แล้ว

    Thanks for this video, very awesome!!

  • @petero1166
    @petero1166 3 ปีที่แล้ว +1

    Hi @
    Corey Schafer How did you get the posts saved in the JSON file to the database?

  • @GTDragonGaming
    @GTDragonGaming 25 วันที่ผ่านมา +1

    22:50 i was having a error in line 148 says "str not found" i removed that "str:" thing and its working now hope it will not give error in future

  • @codevalley9511
    @codevalley9511 2 ปีที่แล้ว

    thank you very sir , u really solve my big problem

  • @joeshindano8842
    @joeshindano8842 5 ปีที่แล้ว

    Best video tutorial on flask pagination ever, but please make a video on flask infinite scrolling if's really exist, it is so hard to find on the internet.

  • @user-cl2vi3iy4r
    @user-cl2vi3iy4r 5 ปีที่แล้ว +8

    Anybody knows how to inject the json of the posts provided into the sqlite at once so I don't have to type all the dummy data?

    • @cdishiyam9232
      @cdishiyam9232 4 ปีที่แล้ว

      where thinking about the same thing

    • @vruttantbalde7187
      @vruttantbalde7187 4 ปีที่แล้ว

      @@farisrizkiekananda5956 Thanks man! Life saving.

    • @henchhh
      @henchhh 4 ปีที่แล้ว

      @@farisrizkiekananda5956 insane man, thanks!

    • @sudhanshujoshi8137
      @sudhanshujoshi8137 4 ปีที่แล้ว

      @@farisrizkiekananda5956 Indeed, this was life saving :)

    • @lepsygoyal283
      @lepsygoyal283 4 ปีที่แล้ว

      @@farisrizkiekananda5956 Thanku bro for this!! :)

  • @nerdydev
    @nerdydev 4 ปีที่แล้ว +2

    I am getting a 'TypeError: 'Pagination' object is not iterable' Error even when using coreys snippets. Any ideas?

    • @omarfaruqeriyad6707
      @omarfaruqeriyad6707 3 ปีที่แล้ว

      Just make sure that you are using the "items" attribute on the pagination object. For example: {% for post in posts.items %}

  • @xinyixiao1394
    @xinyixiao1394 6 ปีที่แล้ว +2

    amazing !Thank you dude!

  • @miqueasbatistadossantos2234
    @miqueasbatistadossantos2234 5 ปีที่แล้ว +1

    I love your videos thank you!

  • @rossgeography
    @rossgeography 4 ปีที่แล้ว

    fyi if implementing next or prev links use {%if posts.has_prev %}Prev

  • @joaomorita3027
    @joaomorita3027 2 ปีที่แล้ว +1

    Great tutorial! Thanks for that!! Guys, how can I add images in my posts?

  • @ian_senior
    @ian_senior 4 ปีที่แล้ว +3

    if you want a script to import all of the posts from the json file, then follow the instructions below which will download the json file to the directory using the command line then you need to go into the python shell and create the posts (make sure you have 2 users already created first with user.id 's 1 and 2). also, if you don't already have wget then you can get it with
    brew install wget
    otherwise, just download the json file anyway you want and put it in Flask_Blog directory and then skip the wget command and start with line 2 - python below...
    on the command line inside the Flask_Blog root directory:
    wget github.com/CoreyMSchafer/code_snippets/blob/master/Python/Flask_Blog/snippets/posts.json
    python
    import json
    from flaskblog import db
    from flaskblog.models import User, Post
    with open('posts.json', 'r') as read_file:
    data = json.load(read_file)
    for record in data:
    user = User.query.get(record['user_id']
    post = Post()
    post.title = record['title']
    post.content = record['content']
    post.author = user
    db.session.add(post)
    db.session.commit()

    • @haseebabbas6305
      @haseebabbas6305 4 ปีที่แล้ว

      hey there.!! bro at post = Post() i'm having this error again and again it says ( >>> with open('posts.json', 'r') as read_file:
      ... data = json.load(read_file)
      ... for record in data:
      ... user = User.query.get(record['user_id']
      ... post = Post()
      File "", line 5
      post = Post()
      ^
      SyntaxError: invalid syntax
      ) what should i do?? i'm a beginner student and new to python.

    • @omarfaruqeriyad6707
      @omarfaruqeriyad6707 3 ปีที่แล้ว

      github.com/riyadomf/Brevity/blob/main/Insert_bulk_posts.py
      How's my script. Any idea for improving speed?

    • @omarfaruqeriyad6707
      @omarfaruqeriyad6707 3 ปีที่แล้ว

      @Angelo Barazon You can manually copy and paste it into a local file.
      Another way is to scrape the json data.
      Here's my script that fetches the json data and inserts it into database automatically. github.com/riyadomf/Brevity/blob/main/Insert_bulk_posts.py
      Make sure you have 2 users already created with user.id 's 1 and 2.

    • @omarfaruqeriyad6707
      @omarfaruqeriyad6707 3 ปีที่แล้ว

      @Angelo Barazon Did you try scraping the link. I also faced the same issue. Then, instead of manually copy pasting, I scraped the json data from the link.

    • @omarfaruqeriyad6707
      @omarfaruqeriyad6707 3 ปีที่แล้ว

      @Angelo Barazon oh, you're welcome and best wishes for your programming journey.

  • @jamespaulchibole266
    @jamespaulchibole266 ปีที่แล้ว

    Your video has made understanding documentation of Flask Pagination very easy. However, I have a question, how do you implement pagination without refreshing the entire page, with only a section of the page refreshed when you move from one page to another? Perhaps with use of Ajax or jQuery.

  • @mignoncharly
    @mignoncharly 5 ปีที่แล้ว +1

    Hey Corey! Thks for this tutorial.
    I used this to jump into Flask and while working with it I got this error "jinja2.exceptions.UndefinedError: 'list object' has no attribute 'iter_pages'" linked to this line code : return render_template('home.html', posts=posts)
    from routes.py
    @app.route("/")
    @app.route("/home")
    def home():
    posts = Post.query.all()
    return render_template('home.html', posts=posts)
    any idea why please? Thks for your time

  • @vinsmokearifka
    @vinsmokearifka 6 ปีที่แล้ว +2

    thank you Corey...

  • @antonboujaoude
    @antonboujaoude 3 ปีที่แล้ว

    Thank you so much for this series, biggest help every and everything makes sense. Is there a way to add a search bar to find a specific post?

  • @RishamHarsimranSingh
    @RishamHarsimranSingh 4 ปีที่แล้ว +1

    I am getting this error when i try to use .iter_pages() method
    TypeError: 'Pagination' object is not iterable
    what should i do?

    • @omarfaruqeriyad6707
      @omarfaruqeriyad6707 3 ปีที่แล้ว

      Just make sure that you are using the "items" attribute on the pagination object. For example: {% for post in posts.items %}

  • @lightninginmyhands4878
    @lightninginmyhands4878 5 ปีที่แล้ว +1

    Corey, how can we make a URL query without a POST method attached to the route?
    Edit: I see now in the docs. url_for() - Variable arguments that are unknown to the target endpoint are *appended to the generated URL as query arguments.*
    Edit 2: Following my first edit, I have an assertion to make about what I see here at 28:39
    Flask checks the `user_posts` view function for variables; it finds `username` as variable for the URL rule, and Flask passes it as such there; on the other hand, `page` is not recognized as a variable and is passed as a query parameter. Is this correct?

    • @sathishj5921
      @sathishj5921 4 ปีที่แล้ว

      I just tested on ur edit 1, additional parameters added to the url_for are being treated as query params

  • @evelyns5218
    @evelyns5218 3 ปีที่แล้ว

    Hi Corey, could you make a video to show us how to add pictures and videos using the wtforms? Thanks so much, your videos have helped me tremendously, would love to put the finishing touches to my blog my adding images and videos. Thanks so much!

  • @ishpeace4886
    @ishpeace4886 5 ปีที่แล้ว

    excellent explanation

  • @smoothinismoothinix5850
    @smoothinismoothinix5850 3 ปีที่แล้ว

    Hi Corey, thanks a lot for your awesome video. Could you also share with us how to use pagination in combination with a filter / search option without loosing the filter value when changing to another page? Thanks a lot.

  • @lightninginmyhands4878
    @lightninginmyhands4878 5 ปีที่แล้ว +1

    AS USUAL....... TREMENDOUS!

  • @samuelnde9917
    @samuelnde9917 5 ปีที่แล้ว +1

    Hey Corey. Thanks for the great work. I would love a video that covers how to display a busy icon like a spinning wheel whenever a process is loading in my flask app. Could you help with that? Thanks.

    • @BT-te9vx
      @BT-te9vx 5 ปีที่แล้ว +1

      once rudimentary way to do that is display a gif - google for loading.gif

    • @samuelnde9917
      @samuelnde9917 5 ปีที่แล้ว

      @@BT-te9vx Thanks man. Still learning sure I am not sure how to implement.

    • @BT-te9vx
      @BT-te9vx 5 ปีที่แล้ว +1

      @@samuelnde9917 i too have been trying to learn for quite some time now - and still am nowhere close to confident but google, stackoverflow are your friends.

  • @rodmaruyama
    @rodmaruyama 5 ปีที่แล้ว +1

    Thank you!

  • @calebmbugua745
    @calebmbugua745 5 ปีที่แล้ว +2

    ASANTE SANA ---(swahili word for thank you!)

  • @sidneysousa3520
    @sidneysousa3520 4 ปีที่แล้ว +1

    This is like Netflix!

  • @pratheeku4467
    @pratheeku4467 3 ปีที่แล้ว

    Hey Corey, the tutorials are great! I have a question. Is there any way that I can incorporate Markdown language to edit my Posts? I mean that would be a great functionality.

  • @nischalsehrawat2130
    @nischalsehrawat2130 4 ปีที่แล้ว

    Hi Corey, would it be possible for you to do a video on plotting graphs as well? Thanks you

  • @omerahmaad
    @omerahmaad 4 ปีที่แล้ว

    Corey can you please have a live session where we can ask you questions?

  • @paulbacol5360
    @paulbacol5360 4 ปีที่แล้ว +2

    Please i need help how do i make a search form?

  • @kamikaze9271
    @kamikaze9271 ปีที่แล้ว +1

    I don't see the dots next to my current page

  • @judyz.7742
    @judyz.7742 5 ปีที่แล้ว

    this is very good tutorial! I am wondering if use SQL Server or any relational database, how to handle data submit and pagination etc?

  • @ronaldlukisi794
    @ronaldlukisi794 ปีที่แล้ว

    Love your tutorials. Do you have a tutorial how to import data from the json file to flask sqlite?

  • @learner3539
    @learner3539 3 ปีที่แล้ว

    @Corey Schafer Can you add a video on Flask Sqlalchemy restful pagination then, it would be great. Thanks for this video.

  • @jayuchawla1892
    @jayuchawla1892 3 ปีที่แล้ว

    why even need to show up anchor tag for username in each post on user_posts route when you already show up 'posts by ....' ?

  • @gongfengliu4332
    @gongfengliu4332 5 ปีที่แล้ว +5

    From the beginning of the video, you did not tell us how to improt json file to SQL......

    • @haseebabbas6305
      @haseebabbas6305 4 ปีที่แล้ว

      hey there... did you find the way how to import json file to sql?? please help me out

  • @el-mzabibadrdine1725
    @el-mzabibadrdine1725 5 ปีที่แล้ว

    hello Corey,
    I want to add one column 'answer' at Post table, like below, but the website couldn't be load. what i need to check please?
    class Post(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(100), nullable=False)
    date_posted = db.Column(db.DateTime, nullable=False, default=datetime.now)
    content = db.Column(db.Text, nullable=False)
    answer = db.Column(db.Text, nullable=True)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
    Here below the error:
    sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) no such column: post.answer
    [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.answer AS post_answer, 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/e3q8)

  • @gauravthakur7071
    @gauravthakur7071 5 ปีที่แล้ว +1

    Alright Everyone, @20:33 sir used "date_posted" but I am using Windows with python version 3.6 & IDLE is pycharm here I needed to use date_post so please help yourself If you got this error. Peace

  • @vvkkumar3691
    @vvkkumar3691 5 ปีที่แล้ว

    Hi Corey Schafer , your contents are really helpful and feel easy to learn . Thank you very much for this flask series . I have done the same 'posts = Post.query.paginate()
    print posts' but getting one error here "UnicodeEncodeError: 'ascii' codec can't encode character u'\u2019' in position 14: ordinal not in range(128)"