Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Aphorismen
Applications
Business Economics & Admin.
My Computers
Cooking
Devices
Folders
Food
Hardware
Infos
Software Development
Sports
Operation Instructions
Todos
Test
Help
Glossary
Community portal
adaptions
Sidebar anpassen
Wiki RB4
Search
Search
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Python
Page
Discussion
English
Read
Edit
View history
Toolbox
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Special pages
Page information
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Resources== * [https://docs.python.org/3.9/tutorial/introduction.html Official Tutorial] * [[Udacity|Udacity Courses]] ==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 <code>C:\Uwes\python\UdacityFullWebDeveloper\testName\</code>). ===Strings=== ====Operators==== '''+''' for concatenation ====String Modifiers==== f'<STRING>' // format modifier u'<STRING>' // unicode ====Output==== print(<STRING>) ==Pip== pip is the standard package manager for Python. ==Virtual Environments== With [https://docs.python.org/3/library/venv.html Venv] it is easy to create virtual environments, obviously using the python version and binaries, which were used to initialize the environment (global environment), as a initial setup. A virtual environment is a subfolder in a project that contains a copy of a specific interpreter. When you activate the virtual environment, any packages you install are installed only in that environment's subfolder. When you then run a Python program within that environment, you know that it's running against only those specific packages. ==Frameworks== ===Flask=== Flask is a micro web framework written in Python. Flask is using a template engine called [https://jinja.palletsprojects.com/en/2.10.x/templates/# Jinja]. The standard to run a Flask application is: $env:FLASK_APP = "flaskr" // folder to look for the init file /flaskr/__init__.py // with method def create_app() or $env:FLASK_APP = "xyz.py" // file with the flask app and then flask run [[--reload]] 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() and to enable debugging and reloading set in Powershell (or call <code>app.run(debug=True)</code>) $env:FLASK_ENV = "development" which starts a http server on port 5000. By default html files are located in a subfolder called 'templates'. They can be rendered by calling <code>render_template()</code>. ====Decorators==== @app.route(<PATH_STRING>[, methods=['<METHOD_LIST']]) // PATH_STRING can have '''<'''<CONVERTER>''':'''<VARIABLE_NAME>'''>''' // request.method contains the Http method ====Flask SQL Alchemy==== * [https://flask-sqlalchemy.palletsprojects.com/en/2.x/quickstart/#simple-relationships Simple Relationships] * [https://docs.sqlalchemy.org/en/14/orm/relationship_api.html#sqlalchemy.orm.relationship Relationship Documentation] * 1-to-many pattern # [[File:FlaskRelationsships.PNG|400px]] # to set a foreign key constraint in database # [[File:FlaskOneToManyPattern.PNG|400px]] * many-to-many patterns ** [[File:FlaskManyToManyPattern.PNG|400px]] ** [https://michaelcho.me/article/many-to-many-relationships-in-sqlalchemy-models-flask here] ** [https://docs.sqlalchemy.org/en/14/orm/basic_relationships.html goto Association Object] ====Flask Migration and Flask Script==== [https://flask-migrate.readthedocs.io/en/latest/ Flask-Migrate] uses the [https://alembic.sqlalchemy.org/en/latest/ Alembic] library, a database migration tool, underneath. It auto-detects changes from the old to the new version of the SQLAlchemy models. It creates migration scripts and enables fine-grain control to change existing tables. <PROJECT_DIR> flask db init // creates initial migrations folder structure, flask db migrate // check the current model in python and the former model in DB and creates versions in migrations folder, it will not create the database but only the schmema flask db upgrade // checks against a database table 'alembic_version' (if there otherwise it will be created) and runs unapplied migrations up to the latest version flask db downgrade =====Installation===== * see [[Python#Installation_2|below]] =====Configuration===== SQLALCHEMY_ECHO = True // prints SQL statements to console ==Operation== ===Comannd Line=== python -V // prints version python >>> <COMMAND> ==Installation== * see [[EDTLaptop1#Python|EDT Win10 Laptop]]
Summary:
Please note that all contributions to Wiki RB4 may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Uwe Heuer Wiki New:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Toggle limited content width