{"id":5626,"date":"2020-01-25T17:52:12","date_gmt":"2020-01-25T16:52:12","guid":{"rendered":"http:\/\/blog.via-internet.de\/?p=5626"},"modified":"2022-04-27T18:44:17","modified_gmt":"2022-04-27T16:44:17","slug":"working-with-azure-and-python","status":"publish","type":"post","link":"https:\/\/via-internet.de\/blog\/2020\/01\/25\/working-with-azure-and-python\/","title":{"rendered":"Python | Working with Azure"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">First Step: Hello World Sample<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The following steps at borrowed from the<a href=\"https:\/\/docs.microsoft.com\/de-de\/azure\/app-service\/containers\/quickstart-python?tabs=bash\"> quick start tutorial.<\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Download sample repository<\/h3>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">$ git clone https:\/\/github.com\/Azure-Samples\/python-docs-hello-world\n$ cd python-docs-hello-world<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Create virtual environment<\/h3>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">$ python3 -m venv venv\n$ source venv\/bin\/activate\n$ pip install -r requirements.txt\n$ export FLASK_APP=application.py\n$ flask run<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Login zu Azure<\/h3>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\" data-enlighter-theme=\"\" data-enlighter-highlight=\"1\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">$ az login<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Deploy to App Service<\/h3>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\" data-enlighter-theme=\"\" data-enlighter-highlight=\"1\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">$ az webapp up --sku F1 -n azure-toolbox-flask-demo -l westeurope\nwebapp azure-toolbox-flask-demo doesn't exist\nCreating Resource group 'xx_xx_Linux_westeurope' ...\nResource group creation complete\nCreating AppServicePlan 'xx_asp_Linux_westeurope_0' ...\nCreating webapp 'flask-demo' ...\nConfiguring default logging for the app, if not already enabled\nCreating zip with contents of dir ...\/Working-with_Python ...\nGetting scm site credentials for zip deployment\nStarting zip deployment. This operation can take a while to complete ...\nDeployment endpoint responded with status code 202\nYou can launch the app at http:\/\/via-internet-flask-demo.azurewebsites.net\n{\n  \"URL\": \"http:\/azure-toolbox-flask-demo.azurewebsites.net\",\n  \"appserviceplan\": \"xx_asp_Linux_westeurope_0\",\n  \"location\": \"westeurope\",\n  \"name\": \"azure-toolbox--flask-demo\",\n  \"os\": \"Linux\",\n  \"resourcegroup\": \"xx_xx_Linux_westeurope\",\n  \"runtime_version\": \"python|3.7\",\n  \"runtime_version_detected\": \"-\",\n  \"sku\": \"FREE\",\n  \"src_path\": \"...\/Working-with_Python\"\n}<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Create Django App with PostgreSQL<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Installation PostgreSQL on Mac OS<\/h3>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">$ brew install postgres\n==> Installing dependencies for postgresql: krb5\n==> Installing postgresql dependency: krb5\n...\n==> Installing postgresql\n...\n==> Caveats\n==> krb5\nkrb5 is keg-only, which means it was not symlinked into \/usr\/local, because macOS already provides this software and installing another version in\nparallel can cause all kinds of trouble.\n\nIf you need to have krb5 first in your PATH run:\n  echo 'export PATH=\"\/usr\/local\/opt\/krb5\/bin:$PATH\"' >> ~\/.bash_profile\n  echo 'export PATH=\"\/usr\/local\/opt\/krb5\/sbin:$PATH\"' >> ~\/.bash_profile\n\nFor compilers to find krb5 you may need to set:\n  export LDFLAGS=\"-L\/usr\/local\/opt\/krb5\/lib\"\n  export CPPFLAGS=\"-I\/usr\/local\/opt\/krb5\/include\"\n\nFor pkg-config to find krb5 you may need to set:\n  export PKG_CONFIG_PATH=\"\/usr\/local\/opt\/krb5\/lib\/pkgconfig\"\n\n==> postgresql\nTo migrate existing data from a previous major version of PostgreSQL run:\n  brew postgresql-upgrade-database\n\nTo have launchd start postgresql now and restart at login:\n  brew services start postgresql\nOr, if you don't want\/need a background service you can just run:\n  pg_ctl -D \/usr\/local\/var\/postgres start<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Set user and passwords for postgres database<\/h3>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Create database and user for django app<\/h3>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">$ psql postgres\npsql (12.1)\nType \"help\" for help.\n\npostgres=# CREATE DATABASE pollsdb;\nCREATE DATABASE\npostgres=# CREATE USER manager WITH PASSWORD '########';\nCREATE ROLE\npostgres=# GRANT ALL PRIVILEGES ON DATABASE pollsdb TO manager;\nGRANT<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Download sample repository<\/h3>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">$ git clone https:\/\/github.com\/Azure-Samples\/djangoapp.git\n$ cd djangoapp<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Create virtual environment<\/h3>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">$ python3 -m venv venv\n$ source venv\/bin\/activate\n$ pip install -r requirements.txt<\/pre>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">$ cat env.sh\nexport DBHOST=\"localhost\"\nexport DBUSER=\"manager\"\nexport DBNAME=\"pollsdb\"\nexport DBPASS=\"supersecretpass\"\n$ . env.sh<\/pre>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">$ python manage.py  makemigrations\nNo changes detected\n$ python manage.py  migrate\nOperations to perform:\n  Apply all migrations: admin, auth, contenttypes, polls, sessions\nRunning migrations:\n  Applying contenttypes.0001_initial... OK\n  Applying auth.0001_initial... OK\n  Applying admin.0001_initial... OK\n  Applying admin.0002_logentry_remove_auto_add... OK\n  Applying admin.0003_logentry_add_action_flag_choices... OK\n  Applying contenttypes.0002_remove_content_type_name... OK\n  Applying auth.0002_alter_permission_name_max_length... OK\n  Applying auth.0003_alter_user_email_max_length... OK\n  Applying auth.0004_alter_user_username_opts... OK\n  Applying auth.0005_alter_user_last_login_null... OK\n  Applying auth.0006_require_contenttypes_0002... OK\n  Applying auth.0007_alter_validators_add_error_messages... OK\n  Applying auth.0008_alter_user_username_max_length... OK\n  Applying auth.0009_alter_user_last_name_max_length... OK\n  Applying polls.0001_initial... OK\n  Applying sessions.0001_initial... OK<\/pre>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"> $ python manage.py createsuperuser\nUsername (leave blank to use 'user'): admin\nEmail address: admin@localhost\nPassword:\nPassword (again):\nSuperuser created successfully.<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Run server and acccess web page at http:\/\/127.0.0.1:8000\/<\/h3>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">$ python manage.py runserver\nPerforming system checks...\n\nSystem check identified no issues (0 silenced).\nJanuary 25, 2020 - 16:42:14\nDjango version 2.1.2, using settings 'azuresite.settings'\nStarting development server at http:\/\/127.0.0.1:8000\/\nQuit the server with CONTROL-C.\n[25\/Jan\/2020 16:42:26] \"GET \/ HTTP\/1.1\" 200 111\n[25\/Jan\/2020 16:42:26] \"GET \/static\/polls\/style.css HTTP\/1.1\" 200 27\nNot Found: \/favicon.ico\n[25\/Jan\/2020 16:42:26] \"GET \/favicon.ico HTTP\/1.1\" 404 2688<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Login zu Azure<\/h3>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\" data-enlighter-theme=\"\" data-enlighter-highlight=\"1\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">$ az login<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Deploy to App Service<\/h3>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\" data-enlighter-theme=\"\" data-enlighter-highlight=\"1\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">$ az webapp up --sku F1 -n azure-toolbox-django-demo -l westeurope\nwebapp azure-toolbox-django-demo doesn't exist\nCreating Resource group 'xx_xx_Linux_westeurope' ...\nResource group creation complete\nCreating AppServicePlan 'xx_asp_Linux_westeurope_0' ...\nCreating webapp 'flask-demo' ...\nConfiguring default logging for the app, if not already enabled\nCreating zip with contents of dir ...\/Working-with_Django ...\nGetting scm site credentials for zip deployment\nStarting zip deployment. This operation can take a while to complete ...\nDeployment endpoint responded with status code 202\nYou can launch the app at http:\/\/via-internet-django-demo.azurewebsites.net\n{\n  \"URL\": \"http:\/azure-toolbox-django-demo.azurewebsites.net\",\n  \"appserviceplan\": \"xx_asp_Linux_westeurope_0\",\n  \"location\": \"westeurope\",\n  \"name\": \"azure-toolbox--django-demo\",\n  \"os\": \"Linux\",\n  \"resourcegroup\": \"xx_xx_Linux_westeurope\",\n  \"runtime_version\": \"python|3.7\",\n  \"runtime_version_detected\": \"-\",\n  \"sku\": \"FREE\",\n  \"src_path\": \"...\/Working-with_Django\"\n}<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"> <\/h2>\n\n\n\n<h2 class=\"wp-block-heading\">Additional Reading<\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/azure.microsoft.com\/de-de\/resources\/videos\/azure-friday-python-on-azure-part-1-building-django-apps-with-visual-studio-code\/\">Microsoft: Python on Azure<\/a><\/li><li><a href=\"https:\/\/code.visualstudio.com\/docs\/languages\/python?ocid=AID754288&amp;wt.mc_id=CFID0237\">Microsoft: Python in Visual Studio Code<\/a><\/li><li><a href=\"https:\/\/docs.microsoft.com\/de-de\/azure\/python\/\">Microsoft: Azure f\u00fcr Python-Entwickler<\/a><\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Installation<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/docs.microsoft.com\/de-de\/cli\/azure\/install-azure-cli?view=azure-cli-latest\">Here<\/a> is the documentation from Microsoft.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Mac OS<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"install-with-homebrew\">Install with Homebrew<\/h4>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">$ brew update &amp;&amp; brew install azure-cli\n$ az login<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>First Step: Hello World Sample The following steps at borrowed from the quick start tutorial. Download sample repository Create virtual environment Login zu Azure Deploy to App Service Create Django App with PostgreSQL Installation PostgreSQL on Mac OS Set user and passwords for postgres database Create database and user for django app Download sample repository Create virtual environment Run server and acccess web page at http:\/\/127.0.0.1:8000\/ Login zu Azure Deploy to App Service Additional Reading Microsoft: Python on Azure Microsoft: Python in Visual Studio Code Microsoft: Azure f\u00fcr Python-Entwickler Installation Here is the documentation from Microsoft. Mac OS Install with Homebrew<\/p>\n","protected":false},"author":1,"featured_media":5653,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_crdt_document":"","_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[9,65],"tags":[],"class_list":["post-5626","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-azure","category-python"],"jetpack_featured_media_url":"https:\/\/via-internet.de\/blog\/wp-content\/uploads\/2020\/01\/azure.jpg","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/via-internet.de\/blog\/wp-json\/wp\/v2\/posts\/5626","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/via-internet.de\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/via-internet.de\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/via-internet.de\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/via-internet.de\/blog\/wp-json\/wp\/v2\/comments?post=5626"}],"version-history":[{"count":1,"href":"https:\/\/via-internet.de\/blog\/wp-json\/wp\/v2\/posts\/5626\/revisions"}],"predecessor-version":[{"id":8817,"href":"https:\/\/via-internet.de\/blog\/wp-json\/wp\/v2\/posts\/5626\/revisions\/8817"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/via-internet.de\/blog\/wp-json\/wp\/v2\/media\/5653"}],"wp:attachment":[{"href":"https:\/\/via-internet.de\/blog\/wp-json\/wp\/v2\/media?parent=5626"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/via-internet.de\/blog\/wp-json\/wp\/v2\/categories?post=5626"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/via-internet.de\/blog\/wp-json\/wp\/v2\/tags?post=5626"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}