====== Язык программирования Python ====== ===== Виртуальная среда Python ===== * [[https://blog.sedicomm.com/2021/06/29/chto-takoe-venv-i-virtualenv-v-python-i-kak-ih-ispolzovat/|Что такое venv и virtualenv в Python, и как их использовать]] * [[https://packaging.python.org/en/latest/guides/installing-using-pip-and-virtual-environments/|https://packaging.python.org/en/latest/guides/installing-using-pip-and-virtual-environments/]] * [[https://www.workroom-productions.com/serving-a-directory-with-flask/|Publishing a Directory with Flask]] # apt install python3-venv $ python3 -m venv ~/venv1 $ source ~/venv1/bin/activate (venv1) $ which python (venv1) $ which ansible (venv1) $ deactivate ===== Web приложение ===== * [[https://python.ivan-shamaev.ru/run-install-deploy-flask-web-app-docker-dockerfile-compose/|Создание Web-приложения Flask и деплой с помощью Docker Compose & Dockerfile]] * [[https://blog.miguelgrinberg.com/post/running-your-flask-application-over-https|Running Your Flask Application Over HTTPS]] * [[https://docs.python.org/3/library/configparser.html|configparser — Configuration file parser]] * [[#Виртуальная среда Python]] (venv1) :~$ pip install Flask (venv1) :~$ mkdir -p pywebd/; cd $_ (venv1) :~/pywebd$ cat app.py from flask import Flask, send_from_directory import os import configparser CONST_VER = "ver1.4" app = Flask(__name__) @app.route('/') def index(): return send_from_directory(pywebd_doc_root, 'index.html') @app.route('/') def sendstuff(path): print(path) return send_from_directory(pywebd_doc_root, path) if __name__ == "__main__": config = configparser.ConfigParser() config.read('/etc/pywebd/pywebd.conf') pywebd_port = os.environ.get('PYWEBD_PORT',config['default']['Listen']) pywebd_doc_root = os.environ.get('PYWEBD_DOC_ROOT',config['default']['DocumentRoot']) app.run(ssl_context=('/etc/pywebd/pywebd.crt', '/etc/pywebd/pywebd.key'), debug=True, host='0.0.0.0', port=pywebd_port) # cat /etc/pywebd/pywebd.conf [default] DocumentRoot = /var/www/ Listen = 8443 (venv1) :~/pywebd$ #export PYWEBD_PORT=4443 (venv1) :~/pywebd$ #export PYWEBD_DOC_ROOT=/var/www/html/ (venv1) :~/pywebd$ python app.py (venv1) :~/pywebd$ pip freeze > requirements.txt ===== Дополнительные материалы ===== ==== Доступ к каталогу по http ==== * [[https://gist.github.com/SeanPesce/af5f6b7665305b4c45941634ff725b7a|SeanPesce/https_server.py]] dir$ python3 -m http.server 80