Python: Difference between revisions

From Wiki RB4
Line 21: Line 21:
  if __name__ == '__main__':
  if __name__ == '__main__':
   app.run()
   app.run()
in Powershell
in Powershell ???
  $env:FLASK_ENV = "development"
  $env:FLASK_ENV = "development"
By default html files are located in a subfolder called 'templates'. They can be rendered by calling <code>render_template()</code>.


====Flask Migration====
====Flask Migration====

Revision as of 12:04, 1 October 2021

Resources

Language

Python, named after the British comedy group Monty Python, is a high-level, interpreted, interactive, and object-oriented programming language.

Comment

# ... till end of line

__name__

The __name__ variable (two underscores before and after) is a special Python variable. It gets its value depending on how we execute the containing script. When you run the script, the __name__ variable equals '__main__'. When you import the script, it will contain the name of the imported script w/o extension (see C:\Uwes\python\UdacityFullWebDeveloper\testName\).

Frameworks

Flask

Flask is a micro web framework written in Python. Flask is using a template engine called Jinja.

To enable to run a flask application as a 'normal' python app with

python <FILE>

add to end of file

if __name__ == '__main__':
 app.run()

in Powershell ???

$env:FLASK_ENV = "development"

By default html files are located in a subfolder called 'templates'. They can be rendered by calling render_template().

Flask Migration

flask db init // creates migrations folder structure
flask db migrate // check the current and the former model in DB and creates versions in migrations folder
flask db upgrade
flask db downgrade

Operation

Comannd Line

python -V // prints version
python
>>> <COMMAND>

Installation