Flask & the Fetch API (AJAX?) - Python on the web - Learning Flask Series Pt. 10

Поділитися
Вставка
  • Опубліковано 26 лис 2024

КОМЕНТАРІ • 74

  • @MatSzub
    @MatSzub Рік тому +3

    I was looking for a clear answer how to perform communication between front to back-end for a long time. And after that I found this tutorial, which is clear and understandable for me as a beginner. Julian Nash - thanks a lot. It gives me a milestone in my first programming project.

  • @michaellk2254
    @michaellk2254 3 роки тому +8

    you have NO IDEA, how MUCH OF A HEADACHE YOU SAVED ME. OH MY GOODNESS. THANK YOU

  • @KirkLHemmett
    @KirkLHemmett 3 роки тому +1

    I just completed my project seeing your video. Great help.

  • @jonsnow9758
    @jonsnow9758 3 роки тому +2

    Best Python Flask Jinja Tutorial available on UA-cam !!! He has explained each and every thing properly.
    That's exactly I was looking for... *Amazing* ....Thanks a ton Julian!!!

  • @joaopaulocoimbra9381
    @joaopaulocoimbra9381 2 роки тому

    Amazed by all the talents Charlie Cox have.

  • @soldadopreciso
    @soldadopreciso 3 роки тому

    Thanks pal, very useful tutorial, greetings from South America. Greetings fro the flask community.

  • @muhammadshafeeq8779
    @muhammadshafeeq8779 3 роки тому

    Thank you soo much for taking your time to do this. I dunno if u hear this a lot but ur special.

  • @brutalbutler
    @brutalbutler 5 років тому +10

    vids are class mate, wish i found them earlier!

  • @jitendra2510
    @jitendra2510 4 роки тому +1

    Thank you very very very very very.....much.
    You saved project.
    Thank you again.

  • @pro_grammar
    @pro_grammar Рік тому

    You really helped me solve a big problem. Bless you

  • @adomassem
    @adomassem 2 роки тому

    Thanks for great tutorial, really helped me with my project!

  • @PeterCorsa
    @PeterCorsa 8 місяців тому

    Hello Julian, thank you for the help. I was hoping to view the json data in the terminal on the web page, what video is that in?

  • @guinea_horn
    @guinea_horn 4 роки тому +1

    Do you have this code up anywhere? It's a bit inconvenient to have to scrub through the video to find bits that I'm referencing in my own application.

  • @BharatChawla55
    @BharatChawla55 2 роки тому

    Bro you just saved my day! Thanks a ton!

  • @zsadezbuchanon2808
    @zsadezbuchanon2808 3 роки тому

    Excellent stuff man. Thank you so much.

  • @junivensaavedra882
    @junivensaavedra882 2 роки тому

    Excellent resource, thank you very much. :)

  • @amd.615
    @amd.615 2 роки тому

    Very Helpful, thAnks to you 👍👍👍

  • @mbuzifromthehood
    @mbuzifromthehood 3 роки тому

    Love your work manze.

  • @wduandy
    @wduandy 4 роки тому +1

    You're an amazing teacher mate, well done!

  • @nguyenhailong6522
    @nguyenhailong6522 4 роки тому

    It hit right the thing I want. Love your video, great content with an example from the server side. I had been struggling with all the documentation which has nothing on the server-side, and I cant understand how and where to send the fetch url, but your video saves me. So thump up for ya !

  • @ik4rus2k
    @ik4rus2k 2 роки тому

    Hey Julian, thanks for the great video! Could you please explain how to actually return the response? i always get "Undefined"

  • @PatHess
    @PatHess 4 роки тому

    very helpful....I'll check out some more of your videos....I did spend some time running down my typos..nothing new there

  • @yashvarshney6761
    @yashvarshney6761 3 роки тому +3

    Tip: Always show code link at the end of the video.

  • @liquathrushbane2003
    @liquathrushbane2003 2 роки тому

    Gah! This video got me. Didn't see (in the previous video) about adding a {% block script %}{% blockend %} in the public_template.html so it took ages to get working. Still, enjoying the series so far.

  • @alharethturab7612
    @alharethturab7612 3 роки тому

    is it possible to send octet-stream inside the json along with other types of data?

  • @stephenthumb2912
    @stephenthumb2912 2 роки тому

    At its basics, it's just a way to perform API POST, GET..., directly from vanilla JS inside the DOM, then you're just communicating with your python backend as normal. For some reason that was confusing at the start.

  • @Sclafus
    @Sclafus 3 роки тому

    Thanks for this amazing tutorial!

  • @annakbballin7
    @annakbballin7 4 роки тому

    Is there a reason an else statement is not included in the .then method?

  • @gamex-animex6289
    @gamex-animex6289 11 місяців тому

    is it possible to send data from flask back to javscript without using jinja?

  • @jonsnow9758
    @jonsnow9758 3 роки тому

    *Need HELP* As per this tutorial I'm sending data with POST request using fetch();
    in my views.py file I'm able to print it in the console. But when I pass it using render_template() to a html file, the table rows which I expect to update are NOT updating.

  • @gabriellsscolaro
    @gabriellsscolaro 2 роки тому

    How to hide this script from the client side, or can I make a post of these values and sent to the back end to do some stuff in a python program (back-ended)

  • @sagnikchakraborty4750
    @sagnikchakraborty4750 5 років тому

    This guy saved me !!! Thank A Lot !!!

  • @krishnapatel6821
    @krishnapatel6821 5 місяців тому

    why use fetch() and not Ajax get or post to retrieve and send data back to server?

  • @ryanhinchliffe7771
    @ryanhinchliffe7771 5 років тому

    Thanks, for making this Video Julian :)

  • @scottcurry3767
    @scottcurry3767 4 роки тому

    Awesome stuff man, this helped me a lot!

  • @Blocks0
    @Blocks0 4 роки тому

    Great tutorial. Thanks!

  • @christophedupin8130
    @christophedupin8130 4 роки тому

    i m getting an error : Fetch error: TypeError: Failed to fetch
    any idea?
    how could the example work :
    response.json().then(function (data)
    response.json() object doesnt have any methode call then and it s note a promise

  • @Imufur
    @Imufur 3 роки тому

    why use this and not a request.args or request.form or something like that?

  • @saurabhagarwal9253
    @saurabhagarwal9253 3 роки тому

    very useful video.. few things need to be updated in the code to make it work error-free

  • @TheCacoVenom
    @TheCacoVenom 2 роки тому

    good explanation but I really want to click and move another route by rendering a template, so far I am in the route but since is not JSON and instead is

  • @EnglishRain
    @EnglishRain 3 роки тому

    Amazing, thank you!

  • @baconmanbro
    @baconmanbro 4 роки тому

    Thanks for your help mate! Last few days was wrapping my mind around this topic, and just clicked while watching this video.

  • @danielandresclavijogiraldo4953
    @danielandresclavijogiraldo4953 3 роки тому

    If you use Token CSRF, I recommend putting this on the headers "X-CSRF-TOKEN": csrf
    Si utiliza Token Csrf, recomiendo poner esto en las cabeceras "X-CSRF-TOKEN": csrf
    Example/Ejemplo:
    csrf = 'Your token'
    headers: new Headers({
    "Content-Type": "application/json",
    "X-CSRF-TOKEN": csrf
    })

  • @m3wt518
    @m3wt518 5 років тому +1

    Hi! I'm getting this error in the console guestbook:72 Uncaught ReferenceError: submit_entry is not defined
    at HTMLButtonElement.onclick (guestbook:72). Could you help please?

    • @m3wt518
      @m3wt518 5 років тому

      oh nevermind the question. I figured it out. Thanks for this tutorial! Very helpful

    • @P-2501
      @P-2501 Рік тому

      @@m3wt518 how did you figure it out? I'm stuck with that issue. Thanks.

    • @P-2501
      @P-2501 Рік тому

      @@m3wt518 Nevermind. I´ve already fixed it. :D

  • @bull2026
    @bull2026 3 роки тому

    Saved my day ..

  • @eugeniogonzato
    @eugeniogonzato 5 років тому

    Helpful, next time will be very good if we will meke a zoom that permits to read you code watching the video from a smart phone

  • @sonny8595
    @sonny8595 4 роки тому

    What would be the reason to use Fetch API, instead of form data as in Pt 7? (Or maybe requests if that is possible?)
    Thanks! I like your videos a lot, very explanatory!
    I also watched the series of Corey Shafer on Flask (which I liked BTW), but yours are more instructive and clearer so far. You use less additional libraries, which let it be more Pythonic.

    • @Tntpker
      @Tntpker 2 роки тому +1

      The advantage of async/fetch/asyncio is that it is non-blocking. Other parts of your code can still be executed when awaiting. Some applications I found fetch to be useful for include polling and checking form content prior to submitting.
      Checking form content:
      What you may want to do is to check that the form content is correct before it is actually submitted. For example, if your user can input a file with only certain type(s) of extension(s), you will want to check if the provided file extension is correct before submitting to the server. If it is not, you give feedback to the user. In JS preventDefault() can be used for this, followed by fetch() after having made sure the form data is correct. A double check on the server side should be done as well (in the file extension example you could use Python's assert keyword)
      Polling:
      If you're doing some computationally expensive task in the background, you may want to use fetch to want to periodically check when the task is completed. You could use Celery to offload an expensive task, and use fetch to poll the server every couple of seconds to check if the task is completed. If you don't do this, your request will time out after a minute or so

  • @manhdannguyen6059
    @manhdannguyen6059 3 роки тому

    Thank you very much

  • @baraasammoud9148
    @baraasammoud9148 5 років тому

    hello julian , really i need you help please , can we use the datatime with flask ?
    can we use the datatime with flask ?
    if yes , please how if we limted two date , means date of start and date of end ?
    :) :)

    • @juliannash3590
      @juliannash3590  5 років тому

      Of course, you can use any Python library with Flask, including datetime.
      Can you explain more about what you're trying to do?

    • @baraasammoud9148
      @baraasammoud9148 5 років тому

      @@juliannash3590 good evening , :)
      I have a file contains two columns the first column contains the values (I have 1 and -1) the second column the date and I have to computer the number of 1 and -1 from a date start and date end.
      u can help me ?

    • @vatsalaykhobragade
      @vatsalaykhobragade 5 років тому

      Yes you can use datetime module for that

  • @adriangonzalez346
    @adriangonzalez346 4 роки тому

    The best!!

  • @sayhellotoroy
    @sayhellotoroy 2 роки тому

    Flask forms would work better in this case I believe

  • @coderpreneur
    @coderpreneur 5 років тому

    awesome video buddy, keep it up ;)

  • @boriskrasilnikovs4717
    @boriskrasilnikovs4717 4 роки тому

    thank you merry much!

  • @fulstak
    @fulstak 5 років тому

    Getting an error: ReferenceError: submit_entry is not defined

    • @jamesm1858
      @jamesm1858 4 роки тому

      If anyone is having this trouble, for me it was because the script block was not being loaded as i was missing {% block script %}{% endblock %} in the template.

  • @vavkus
    @vavkus 5 років тому

    thanks, helpfull example!.

  • @unclegood
    @unclegood 4 роки тому

    Thanks for the video!
    A question about ${window.origin}. What programming language is that?
    It does not seem to work for me, I use the below instead.
    fetch(window.location.href+'getjson',{
    Do you know if there is any difference?

    • @maxgruntgens9000
      @maxgruntgens9000 4 роки тому +2

      It's JavaScript and a more modern feature called string interpolation by Template Literals. ${variable} inside backticks will be read out, computed, and put into the resulting string, Example: const name = "yichuan"; console.log(`My name is ${name}`); // Prints "My name is yichuan". See developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals
      You are using "old style" string concatination syntax.

  • @Emphraim13
    @Emphraim13 5 років тому

    Thanks you saved my ass

  • @mateoscarafia5110
    @mateoscarafia5110 4 роки тому

    coooolll

  • @ivanmclennon
    @ivanmclennon 3 роки тому +1

    this was really fun, shame your channel's dead

  • @anarabiyev9766
    @anarabiyev9766 3 роки тому

    Videos and explanation are great, but I feel like the videos go from "Flask Tutorial" to "HTML tutorial". I fully get that they are related, but I would be happier I you mainly talked about the basics and main concepts of flask without going into coding of HTML.

  • @MegaMooj
    @MegaMooj 10 місяців тому

    This is great content. Thank you!