Flask Web Development in Python - 3 - Variables in your HTML

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

In this Flask tutorial, we're going to be talking about how to pass logic from Python to HTML, incorporate templates, and variables. Logic actually ends up being more like having logic in our HTML. We can do things like having For loops and if statements in our Python.

Passing variables from our Flask Python files to HTML is fairly simple, and using Templates can save us a lot of time.

Something like for each element in a list, place in a table, is completely possible.

We also cover using try-except for error handling. It can be useful to have the exceptions logging the errors in a log file at the very least.

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

Maybe you tried this already, but this works for me:
app.run(host='0.0.0.0', debug=True)
... i.e. a non-apache server like python a_flask_app.py.

Maybe this is the solution for apache2 with mod_wsgi:

slipthetrap
Автор

It would have been much more better if you could show vice-versa also (from html to python)

Sree-qrib
Автор

How can I pass a variable from the web app to the python code?

OviedoSaul
Автор

For debug on a remote server this worked for me - in __init__.py:

from flask import Flask

app = Flask(__name__)

from werkzeug.debug import DebuggedApplication
app.debug = True
app.wsgi_app = DebuggedApplication(app.wsgi_app, evalex=True)

@app.route('/')
def homepage():
result = 10/0
return "Goodbye World"

if __name__ == "__main__":
app.run(debug=True)

kiwiron
Автор

It would have been much it you would SLOW DOWN a little, not everyone know this stuff and that it why we are watching your videos so please slow down a little.

onmyworkbench
Автор

Love the way you explain things... Thanks again ... :)

patrickslomian
Автор

Amazing! thank you very much for sharing your knowledge

wisearchitect
Автор

If you still need debugging still, try
app.run(debug=True)

MRAQWERTY
Автор

hi, you might not want to reload apache everytime(especially if other apps are running in it). Instead you can use 'WSGIScriptReloading On' in your Apache flaskapp.config file and then just use 'touch flaskapp.wsgi' command. This way your changes will reflect immediately.

insaneviruss
Автор

This video is pretty old now but maybe you'll still see this!! You've got my like and sub but I do have a question. How could I go about making my variable more dynamic? I'm taking in info at a contact me page and it redirects to a thank you page but I want to be able to dynamically thank them by name. Is this explained at all in a different video of yours? Thanks (:

productosequis
Автор

Can anyone tell me how to specify the python version which runs the __init__.py?
I almost tried every method:
The default virtual env python version has been changed to python 3.4. This can be checked by
$ python --version
I also add 
#! /usr/bin/python3.4 to wsgi file and the __init__.py.

However, when I output the python version in the browser, it is still 2.6!!

chenwang
Автор

hello few questions here, I set up everything correctly and when I run server "Hi there, how ya doin?" this shows up but I don't have __init__.py file inside /var/www/FlaskApp/FlaskApp. this is my first time working with ssh and ftp. I usually work from sublime ide never have deployed it. Can someone explain to me why we are using remote site section of filezilla instead of building it in local site first then deploying it?

engkortheng
Автор

Give yourself a little treat, instead of using Idle (since its fine for testing stuff but pretty basic for everything else) I would download and install PyCharm. They have a free community edition which is fantastic, has HTML plugin support and all that stuff. And maybe use IPython instead of Idle too, it has things like tab completion.

ViaNocturna
Автор

Hii, would u like to help me to create db sync between python flask server which is having mysql db and android application which has sqlite. You can assume that i want to make a chat application where both are client and both are the server means it should work bidirectional.

codenaman
Автор

Hi, I have a python script written in Jupyter Notebook and uses the pandas library. It has a function at the end which takes a few arguments and produces a json file. I have written an html file with a dropdown menu which shows me which name I selected on the webpage. But I do not know how to get this string as an argument for my python script and then run my python script to produce the json file. Everything is done on localhost for now, how could I solve this issue? Any help would be appreciated, thanks

rrluckyrocky
Автор

Hi Harrison, I know that this video is from a while ago, but I found that I can use pycharm as a replacement for all these tools listed here. I use a mac, but this could easily be done in windows or linux.

You can set up SFTP over a remote server through pycharm and push code that way directly to the server. You can also clone an entire directory and have the changes uploaded automatically. Also, with the terminal built in, everything is right there in my dock. I can restart apache from pycharm.

Note, the remote server has to be configured from the professional license... so there is that.

The last tool I think might be good for beginners is bootstrap studio. It makes building websites a piece of cake, and the user can focus on the logic behind python as opposed to learning a different front end language.

Thanks again for all your videos!

SerottaPDX
Автор

4:20 You can check apach2 error.log to know why it is not working!
# tail -f /var/log/apache2/error.log

abdullah
Автор

Why not say os.system(“apache2 restart”) in the start of the Python file

arjunbemarkar
Автор

Your videos are excellent and you make me laugh:-). Great sense of humor. Thanks for your tutorials, keep on doing!

sandrolosa
Автор

How to pass string having special characters like quotes or colons? thnx

nikhil