Flask Web Development in Python - 4 - HTML Logic

preview_player
Показать описание

In this Flask tutorial we continue the topic of logic and templates. Here, we cover an example of the for loop and if statement, as well as if else.

Bitcoin donations: 1GV7srgR4NJx4vrk7avCmmVQQrqmv87ty6
Рекомендации по теме
Комментарии
Автор

These tutorials are INVALUABLE. Thank you for making them! I have learned so much from you. Looking forward to seeing how I can best help others learn what I have learned.

writingpanda
Автор

ive watched several videos on flask, and I finally grasped it after this tutorial :)  Awesome job sentDex

eddwinnas
Автор

Hi, I have a question that in route("/" ) we are using render template but if it redirects me to a webpage using redirect_url(google.com) how will it come bask to hit another route in flask program as we cannot wirite a redirect/return in same route .example code


@app.route("/", methods=['GET', 'POST'])
def home():
@app.route("/", methods=['GET', 'POST'])
def posted_data():
print("i am triggered")
if request.method=='POST':
print("its a post method")
data=request.form("s")
print(data)

hokapokas
Автор

Harrison, you are a GENIUS! - We love you. Lots of love from India!

omkarbhatt
Автор

It doesn't work for me, I can't pass the title values into the html, it just comes blank...

skybrightmiracle
Автор

how about html buttons with python onclick functions?

cxl
Автор

I really don't think it's a good practice what is suggested in this video regarding the use of just one or two templates to contain multiple logically distinct pages.

Sorry if the analogy is not very creative, but that's like eating a three-course meal all in one plate (and using just a fork)!

Proper separation of concerns and keeping code short is paramount to creating maintainable code, something that any programmer comes to appreciate after a few years of practice.

exmachina
Автор

No NO NO! IT's stinks like PHP!
Who first had that idea of mix markup with logic?
Would be way easier to send the data in json and parse it in vanilla Javascript!
AAARGH! I wanna punch someone in the face!

ricardo.mazeto
Автор

Hi sentdex,

I just realized the following problem:

if I try to define and call a varibale within a function the whole script fails to start (something about indention level, but this has nothing to do with it). However, if I define the varibale outside the function and call it within it works.

Can this have something to do with me using Python 3?

TheddunTOSS
Автор

if you suddenly have thousands of people visitng your website, and you have logic in the html file. is that going to overload the server? i mean, what are the numbers when it comes to flask performance etc. should you do logic in the html file or in the python backend? for example if someone refreshes the page over and over does it calculate the html logic, and iterate over the list every time someone refreshes the page? just putting it out there.

fergus
Автор

super helpful videos, any tips on using tuples in flask?

joeacanfora