Django file upload keyerror

django file upload keyerror

I think i found the answer. In PIL documentation i see that ICO is read-only, but i try to do write operation. This is the problem. Uploading non-ascii filename causes error by UnicodeEncodeError. If the form has two (or more) input fields for uploading files. I am using python & django I want to upload to upload a 'csv' file and read data inorder to insert it into database(postgresql). django file upload keyerror

That interrupt: Django file upload keyerror

Django file upload keyerror
Apache virtual host ssl_error_rx_record_too_long
Django file upload keyerror
Django file upload keyerror

Issues

Uploading non-ascii filename causes error by UnicodeEncodeError.

If the form has two (or more) input fields for uploading files,
and if you fill in either field by non-ascii filename and the other
field empty, then an UnicodeEncodeError occurs when is_valid() is invoked.

To the contrary, no error occurs when
(1) the form has only one input field and fill it by non-ascii filename,
(2) or the form has two (or more) input fields and fill them all by filenames.
(3) or fill one or more input field(s) by ascii filename(s)

I wonder why the error occurs only on condition that
(4) the form has two (or more) input fields and one field is filled by
non-ascii filename and the other field(s) is/are kept empty.

[1] source code

[ sprers.eu ] class UploadForm(sprers.eu): attach_1 = sprers.eueld(required = False) attach_2 = sprers.eueld(required = False) def test_upload(self,request): if sprers.eu == 'POST': formup = UploadForm(sprers.eu,sprers.eu) if sprers.eu_valid(): result = sprers.eu_uploaded_file(sprers.eu) return HttpResponseRedirect('sprers.eu') * the form page is encoded in UTF [2] error message UnicodeEncodeError at /mysite1/debug/sprers.eu 'ascii' codec can't encode characters in position ordinal not in range() Unicode error hint The string that could not be encoded/decoded was: NON-ASCII-UPLOAD-FILENAME [3] traceback message Traceback: File "/usr/lib/python25/Lib/site-packages/django/core/handlers/sprers.eu" in get_response response = callback(request, *callback_args, **callback_kwargs) File "/mysite1/debug/sprers.eu" in upload return sprers.eu_upload(request) File "/mysite1/debug/util_mysite_sprers.eu" in test_upload if sprers.eu_valid(): File "/usr/lib/python25/Lib/site-packages/django/forms/sprers.eu" in is_valid return sprers.eu_bound and not bool(sprers.eu) File "/usr/lib/python25/Lib/site-packages/django/forms/sprers.eu" in _get_errors sprers.eu_clean() File "/usr/lib/python25/Lib/site-packages/django/forms/sprers.eu" in full_clean value = sprers.eu_from_datadict(sprers.eu, sprers.eu, sprers.eu_prefix(name)) File "/usr/lib/python25/Lib/site-packages/django/forms/sprers.eu" in value_from_datadict return sprers.eu(name, None) File "/usr/lib/python25/Lib/site-packages/django/utils/sprers.eu" in get val = self[key] File "/usr/lib/python25/Lib/site-packages/django/utils/sprers.eu" in __getitem__ raise MultiValueDictKeyError, "Key %r not found in %r" % (key, self) File "/usr/lib/python25/Lib/site-packages/django/utils/sprers.eu" in __repr__ super(MultiValueDict, self).__repr__()) Exception Type: UnicodeEncodeError at /mysite1/debug/sprers.eu Exception Value: 'ascii' codec can't encode characters in position ordinal not in range()

Django and Static Assets

Last updated July 28,

WhiteNoise

Django does not support serving static files in production. However, django file upload keyerror, the fantastic WhiteNoise project can integrate into your Django application, and was designed with exactly this purpose in mind.

See the WhiteNoise Django documentation for more details.

There is also a full example in the Getting Started with Python project on GitHub.

Collectstatic during builds

When a Django application is deployed to Heroku, is run automatically during the build. A build will fail if the collectstatic step is not successful.

Debugging

If collectstatic failed during a build, a traceback was provided that will be helpful in diagnosing the problem, django file upload keyerror. If you need additional information django file upload keyerror the environment collectstatic was run in, use the configuration.

This will display in your build output all of the environment variables that were available to Python when the collectstatic command was executed.

Disabling Collectstatic

Sometimes, you may not want Heroku to run collectstatic on your behalf. You can ml 1640 internal error false the collectstatic build step with the configuration:

This will fully disable the collectstatic step of the build.

[FIXED] KeyError while reading a CSV file in Python

I am trying to plot the fall of an object (an optical fork to be precise) as a function of time in order to verify that the law of gravity is indeed The different data are supposed to represent the passage at each slot. The different slits are django file upload keyerror 1 centimeter apart and there are 11 slits in all. I measured these data with an Arduino setup and I plot the graph and fit with Python. I have the data in a CSV file but when I run my code, I get an

I don't understand because the column T (s) is present in my DataFrame.

Here is my CSV File with name 'sprers.eu' (I specify that I don't want to select the first and last value of column T (i.e. and ) and that I don't want to read the Distance column):

T (s)Distance (m)

And here is my code:

Do you know where this error can come from?


Actually looking at the sprers.eu it seems that the separator,at least judging by the column name, is a semicolon. Also the column name should be "Time (s)". Please try:



Answered By - Jayvee
This Answer collected from stackoverflow and tested by PythonFixing community admins, is licensed under cc by-sacc by-sa and cc by-sa

create a view for uploading a .csv file and parsing it on the template but it&#;s returning a

MultiValueDictKeyError at / 'file'

The template has

Then my views has

import csv, io from sprers.euuts import render from sprers.eub import messages def data_upload(request): template = "sprers.eu" if sprers.eu == 'GET': return render(request, django file upload keyerror, template) csv_file = sprers.eu['file'] if not csv_sprers.euth('.csv'): sprers.eu(request, 'Please upload a .csv file.') data_set = csv_sprers.eu().decode('UTF-8') io_string = sprers.euIO(data_set) next(io_string) for column in sprers.eu(io_string, delimiter=',', quoteschar="

Deploy a Python (Django or Flask) web app with PostgreSQL in Azure

  • Article
  • 33 minutes to read

In this tutorial, you'll deploy a data-driven Python web app (Django or Flask) with the Azure Database for PostgreSQL relational database service. The Python app is hosted in a fully managed Azure App Service which supports Python or higher in a Linux server environment. You can start with a basic pricing tier that can be scaled up at any later time.

An architecture diagram showing an App Service with a PostgreSQL database in Azure.

To complete this tutorial, you'll need:

1 - Sample application

Sample Python applications using the Flask and Django framework are provided to help you follow along with this tutorial. Download or clone one of the sample applications to your local workstation.

To run the application locally, navigate into the application django file upload keyerror a virtual environment for the app:

Install the dependencies:

Note

If you are following along with this tutorial with your own app, look django file upload keyerror the sprers.eu file description in each project's sprers.eu file (Flask, Django) to see what packages you'll need.

This sample application requires an .env file describing how to connect to your local PostgreSQL instance. Create an .env file as shown below using the sprers.eu file as a guide. Set the value of to the name of an existing database in your local PostgreSQL instance. This tutorial assumes the database name is restaurant. Set the values of, and as appropriate for your local PostgreSQL instance.

For Django, you can use SQLite locally instead of PostgreSQL by following the instructions in the comments of the sprers.eu file.

Create the and database tables:

Run the app:

In a web browser, go to the sample application at and add some restaurants and restaurant reviews to see how the app works.

A screenshot of the Flask web app with PostgreSQL running locally showing restaurants and restaurant reviews.

In a web browser, go to the sample application at and add some restaurants and restaurant reviews to see how the app works.

A screenshot of the Django web app with PostgreSQL running locally showing restaurants and restaurant reviews.

Tip

With Django, you can create users with the command like you would with django file upload keyerror typical Django app. For more information, see the documentation for django django-admin and sprers.eu Use the superuser account to access the portion of the web site. For Flask, use an extension such as Flask-admin to provide the same functionality.

Having issues? Let us know.

2 - Create a web app in Azure

To host your application in Azure, you need to create Azure App Service web app.

Sign in to the Azure portal and follow these steps to create your Azure App Service resource.

InstructionsScreenshot
In the Azure portal:
  1. Enter app services in the search bar at the top of the Azure portal.

  2. Select the item labeled App Services under the under Services heading on the menu that appears below the search bar.

A screenshot showing how to use the search box in the top tool bar to find App Services in Azure portal.
On the App Services page, select + Create.A screenshot showing the location of the Create button on the App Services page in the Azure portal.
On the Create Web App page, fill out the form as follows:
  1. Resource Group → Select Create new and use a name of msdocs-python-postgres-webapp-rg.

  2. Name → Use msdocs-python-postgres-webapp-<unique-id>. The name must be unique across Azure with the web app's URL ).

  3. Runtime stackPython

  4. Region → Any Azure region near you.

  5. App Service Plan → Select Create new under Linux Plan and use the name of msdocs-python-postgres-webapp-plan.

  6. App Service Plan → Select Change size under Sku and size to select a different App Service plan.

A screenshot showing how to fill out the form to create a new App Service in the Azure portal.
In the Spec Picker section, select an App Service plan. The App Service plan controls how many resources (CPU/memory) are available to your app and the cost of those resources.
  1. Select Dev/Test.

  2. Select B1 (Basic) Plan.

    The B1 Basic plan will incur a small charge against your Azure account but is recommended for better performance over the F1 (Free) plan.

  3. Select Apply.

A screenshot showing how to select the basic App Service plan in the Azure portal.
Back on the Create Web App page, select the Review + create button at the bottom of the screen.

This will take you to a page to review the configuration. Select Create to create your App Service.
A screenshot showing the location of the Review plus Create button in the Azure portal.

To create Azure resources in VS Code, you must have the Azure Tools extension pack installed and be signed into Azure from VS Code.

InstructionsScreenshot
Locate the Azure icon in the left-hand toolbar and select it to bring up the Azure Tools for VS Code extension.

If you do not see the Azure tools icon, make sure you have the Azure Tools extension for VS Code installed.
A screenshot showing how to find the VS Code Azure extension in VS Code.
In the Azure Tools extension:
  1. Expand RESOURCES and find your subscription, django file upload keyerror. (Make sure resources are grouped by resource type.)

  2. Right-click App Services in your subscription.

  3. Select Create New Web App(Advanced).

A screenshot showing how to create a new web app in VS Code.
In the dialog box at the top of the screen, enter the name of msdocs-python-postgresql-webapp-<unique-id> for this web app.

The name must be unique across Azure, django file upload keyerror. When deployed, this name is used in the DNS name of the web app is .
A screenshot showing how to use the search box in the <i>django file upload keyerror</i> tool bar of VS Code to name a new web app.
Select Create New Resource Group and enter msdocs-python-postgres-webapp-rg in the prompt, if the resource group does not already exist.A screenshot showing how to use the search box in the top tool bar of VS Code to create a new resource group.A screenshot showing how to use the search box in the top tool bar of VS Code to name a new resource group.
Select the runtime stack for the application. For this example, django file upload keyerror, select Python .A screenshot showing how to use the search box in the top tool bar of VS Code to set the runtime stack of a web app in Azure.
Select a region/location near you, such as .A screenshot showing how to use the search box in the top tool bar of VS Code to set location for new web app resource in Azure.
Configure Linux App Service Plan:
  1. Select Create new App Service plan.

  2. Enter msdocs-python-postgres-webapp-plan or use the auto-generated name.

A <i>django file upload keyerror</i> showing how to use the search box in the <i>django file upload keyerror</i> tool bar of VS Code to create a new App Service plan in Azure.A screenshot showing how to use the search box in the top tool bar in VS Code to name a new App Service plan in Azure.
Select the App Service plan pricing tier for this web app.

The App Service plan controls how many resources (CPU/memory) are available to your app and how much you pay. For this example, django file upload keyerror, it's recommended to select the Basic (B1) Develop and test pricing tier. This will incur a small cost in your Azure subscription but provides better performance than the Free (F1) tier.
A screenshot showing how to use the search box in the top tool bar in VS Code to select a pricing tier for a web app in Azure.
Skip adding Application Insights to your web app by selecting Skip for now.

After the last choice, the Azure starts to create the app service.
A screenshot showing how to use the search box in the top tool bar of VS Code to skip configuring Application Insights for a web app in Azure.
View the output and browse to the website:
  1. When a message appears indicating that the new App Service was created, select View Output to switch to the Output window in VS Code.

  2. To confirm that the App Service is running properly, right-click the App Service name, and select Browse Website.

  3. Because you haven't deployed your own code to the App Service yet (which you do in a later step), only a default app page appears.

A screenshot showing deployment with Visual Studio Code and View Output Button.A screenshot showing deployment with Visual Studio Code and how to view App Service in Azure portal.A screenshot showing the default App Service web page when no app has been deployed.

Azure CLI commands can be run in the Azure Cloud Shell or on a workstation with the Azure CLI installed.

Step 1. Create a resource group using the az group create command. A resource group will act as a container for all of the Azure resources related django file upload keyerror this application.

  • location → A location near you, for example. Use to list locations.
  • name → You will use this resource group to organize all the Azure resources needed to complete this tutorial. (for example, )

Step 2. Create an App Service plan using the az appservice plan create command.

  • name → Name for the Azure Web App plan,
  • resource-group → Use the same resource group name you used when you created the web app, django file upload keyerror, for example .
  • sku → Defines the size (CPU, memory) and cost of the app service plan. This example uses the B1 (Basic) service plan, which will incur a small cost in your Azure subscription. For a full list of App Service plans, view the App Service pricing page.
  • is-linux → Selects Linux django file upload keyerror the host operating system.

Step 3. Create the App Service web app using the az webapp create command.

  • name → The app service name is used as both the name of the resource in Azure and to form the fully qualified domain name for your app in the form of the server endpoint. This name must be unique across all Azure and the only allowed characters are - - and. For example, use where is any three django file upload keyerror → The runtime specifies what version of Python your app is running. This example uses Python . To list all available runtimes, use the command .
  • plan → Use the same app service plan name from Step 2. ()
  • resource-group → Use the same resource group name from Step 1. ()

Note

This tutorial shows step-by-step use of Azure CLI commands to reinforce the logical steps that go into creating and deploying an App Service. Once you get familiar with the steps, django file upload keyerror, you can try the that creates a webapp and deploys its code from a local workspace to App Service.

Having issues? Refer first to the Troubleshooting guide, otherwise, let us know.

3 - Create the PostgreSQL database in Azure

You can create a PostgreSQL database in Azure using the Azure portal, Visual Studio Code, or the Azure CLI.

Sign in to the Azure portal and follow these steps to create your Azure Database for PostgreSQL resource.

InstructionsScreenshot
In the Azure portal:
  1. Enter postgres in the search bar at the top of the Azure portal.

  2. Select the item labeled Azure Database for PostgreSQL flexible servers under the under Services heading on the menu that appears below the search bar.

A screenshot showing how to use the search box in the top tool bar to find Postgres Services in the Azure portal.
On the Azure Django file upload keyerror for PostgreSQL flexible servers page, select + CreateA screenshot showing the location of the Create button on the Azure Database for PostgreSQL servers page in the Azure portal.
On the next page, select Create under Flexible server.A screenshot showing the location of the Create Flexible Server button on the Azure Database for PostgreSQL deployment option page in the Azure <b>django file upload keyerror</b> the <strong>Flexible server</strong> page, fill out the form as follows: <ol><li><p><strong>Resource group</strong> → Select and use a name of <em>msdocs-python-postgres-webapp-rg</em>.</p></li><li><p><strong>Server name</strong> → Enter a name such as <em>msdocs-python-postgres-webapp-db-<unique-id></em>. The name must be unique across Azure with the database server's URL ). Allowed characters are - - and .</p></li><li><p><strong>Region</strong> → Same Azure region used for the Web App.</p></li><li><p><strong>Data source</strong> → <strong>None</strong></p></li><li><p><strong>Workload type</strong> → <strong>Production</strong></p></li><li><p><strong>Compute + storage</strong> → Select <strong>Configure server</strong> to select a different Compute + storage plan, which is discussed below.</p></li><li><p><strong>Availability zone</strong> → Keep the default (which is no preference).</p></li><li><p><strong>Version</strong> → Keep the default (which is the latest version).</p></li></ol></td><td><img src=
On the Compute + storage page, continue configuring the flexible server:
  1. Compute tier → Select Burstable.

  2. Compute size → Select Standard_B1ms.

  3. Select Save to return to the main configuration page.

A screenshot showing how to select and configure the basic database service <b>django file upload keyerror</b> in the Azure portal.
Back on the main Flexible server page, finish the basic configuration:
  1. Administrator account → Enter a Admin username and Password to be used for the database administrator account.

  2. Select Next: Networking at the bottom of the screen.

Creating administrator account information for the PostgreSQL Flexible server in the Azure portal.
On the Networking page, add a firewall rule that allows your local environment to access the database server:
  1. Select Add current client IP address to allow access from your local environment.

  2. Select Review + Create at the bottom of the screen, django file upload keyerror.

    This will take you to the Review page. Select Create to create your Azure Database for PostgreSQL Flexible Server Service.

A screenshot showing adding current IP as a firewall rule for the PostgreSQL Flexible server in the Azure portal.

In your local environment using the PostgreSQL interactive terminal psql, connect to the PostgreSQL database server, and create the database:

The values of and are the values from a previous step. If you have trouble connecting, restart the database and try again.

Optionally, verify that the database was successfully created by running to change the prompt from (default) to the. Type to show help or to quit.

Follow these steps to create your Azure Database for PostgreSQL resource using the Azure Tools extension pack in Visual Studio Code.

InstructionsScreenshot
In Visual Studio Code, select the Azure Tools extension. Sign into Azure, if you haven't already.A screenshot showing how to open Azure Extension for Database in VS Code.
In the Azure Tools extension:
  1. Expand RESOURCES. (Make sure resources are sorted by resource type.)

  2. Under your subscription, right-click PostgresSQL servers (Flexible) and select Create Server.

A screenshot showing how create a database server in VSCode.
Select PostgreSQL Flexible Server from the list.A screenshot how to create a new resource in VS Code.
In the VS Code prompts, enter the following information:
  1. Server name → Enter a name for the database server that's unique across all Azure (the database server's URL becomes ). Allowed characters are - - django file upload keyerror, and. For example: msdocs-python-postgres-webapp-db-<unique-id>.

  2. Select the Postgres SKU and options → Select B1ms Basic, 1 vCore, 2GiB Memory, 32GB storage.

  3. Administrator Username and Administrator Password → Enter credentials for an administrator account on the database server. Record these credentials as you'll need them later in this tutorial.

  4. Select a resource group → Select the resource group you created the App Service in, django file upload keyerror, for example msdocs-python-postgres-webapp-rg.

  5. Select a location → Select the same location as the App Service.

A screenshot showing how to create a new resource in the VS Code - server name.A screenshot showing how to create a new resource in VS Code - SKU.A screenshot showing how to create a new resource in VS Code - admin account name.A screenshot showing how to create a new resource in VS Code - admin account password.A screenshot showing how to create a new resource in VS Code - resource group.A screenshot showing how to create a new resource in VS Code - location.
Once the database is created, configure access from your local environment to the PostgreSQL database server:
  1. Open the django file upload keyerror Palette (Ctrl + Shift + P).

  2. Search for select PostgreSQL: Configure Firewall.

  3. Select a subscription if prompted.

  4. Select the database you created above, for example msdocs-python-postgres-webapp-db-<unique-id>, django file upload keyerror. If the database name doesn't appear in the list, it's likely it hasn't finished being created.

  5. Select Yes in the dialog box to add your IP address to the firewall rules of the PostgreSQL server.

A screenshot showing how to configure access for a database by configuring a firewall rule in VS Code.A screenshot showing how to select the correct PostgreSQL server to add a firewall rule in VS Code.A screenshot showing a dialog box asking to add firewall rule for local IP address in VS Code.
After the firewall rule allowing local access has been successfully added, create the database, django file upload keyerror.
  1. Select Azure icon the activity bar.

  2. Select Databases.

  3. Under your subscription, find the PostgreSQL Server you created (for example, msdocs-python-postgres-webapp-db-<unique-id>), right-click and select Create Database.

  4. Enter restaurant as the Database Name.

If you have trouble creating the database, the server may still be processing the firewall rule from the previous step. Wait a moment and try again.
A screenshot showing how to create a PostgreSQL database server in VS Code.

Run to sign in to and follow these steps to create your Azure Database for PostgreSQL resource.

Step 1. Run the az postgres flexible-server create command to create the PostgreSQL server and database in Azure using the values below. It is not uncommon for this command to run for a few minutes to complete.

  • resource-group → Use the same resource group name in which you created the web app, for example .

  • name django file upload keyerror The PostgreSQL database server name. This name must be unique across all Azure (the server endpoint becomes ). Allowed characters are - - and. A good pattern is to use a combination of your company name and server identifier. ()

  • location → Use the same location used for the web app.

  • admin-user → Username for the administrator account. It can't be,or. For example, is okay.

  • admin-password Password of the administrator user. It must contain 8 to characters from three of the following categories: English uppercase letters, django file upload keyerror, English lowercase letters, numbers, and non-alphanumeric characters.

    Important

    When creating usernames or passwords do not use the character, django file upload keyerror. Later you create environment variables with these values where the character has special meaning within the Linux container used to run Python apps.

  • public-access → which sets the server in public access mode with no firewall rules. Rules will be created in a later step.

  • sku-name → The name of the pricing tier and compute configuration, for example. Follow the convention {pricing tier}{compute generation}{vCores} set create this variable. For more information, see Azure Database for PostgreSQL pricing.

  • tier

Step 2. Configure the firewall rules on your server by using the az postgres flexible-server firewall-rule create command to give your local environment access to connect to the server.

  • resource-group → Use the same resource group name in which you created the web app, for example .
  • name → The PostgreSQL database server name.
  • rule-nameAllowMyIP.
  • start-ip-address → equal to your IP django file upload keyerror. To get your current IP address, see sprers.eu
  • end-ip-address → equal to start-ip-address.

Step 3. (optional) You can retrieve connection information using the az postgres server show. The command outputs a JSON object that contains connection strings for the database along and the name.

  • resource-group → The name of resource group you used, for example, msdocs-python-postgres-webapp-rg.
  • name → The name of the database server, django file upload keyerror, for example, msdocs-python-postgres-webapp-db-<unique-id>.

Step 4. In your local environment using the PostgreSQL interactive terminal psql, connect to the PostgreSQL database server, and create the database.

The values of and are the values from a previous step. If you have trouble connecting, restart the database and try again.

Step 5.(optional) Verify database was successfully created by running to change the prompt from (default) to .

Type to show help or to quit.

Having issues? Let us know.

4 - Allow web app to access the database

After the Azure Database for PostgreSQL server is created, configure access to the server from the web app by adding a firewall rule. This can be done through the Azure portal or the Azure CLI.

If you're working in VS Code, right-click the database server and select Open in Portal to go to the Azure portal. Or, go to the Azure Cloud Shell and run the Azure CLI commands.

InstructionsScreenshot
Add a rule to allow your web app to access the PostgreSQL Flexible server.
  1. In the left resource page for the server, select Networking.

  2. Select the checkbox next to Allow public access from any Azure service within Azure to this server.

  3. Select Save to save the change.

To further secure communication between production web apps and database servers, you should use an Azure Virtual Network.
A screenshot showing how to add access from other Azure services to a PostgreSQL database in the Azure portal.

Create a rule that allows other Azure services to connect to the PostgreSQL server by using the az postgres server firewall-rule create command.

  • resource-group → Name of resource group from earlier in this tutorial. ()
  • server → Name of the server from Step 1. ()
  • name → Name traffic inspector error firewall rule. (use )
  • start-ip-address, django file upload keyerror, end-ip-address → signals that access will be from other Azure services. This is sufficient for a demonstration app, but for a production app you should use an Azure Virtual Network.

Having issues? Refer first to the Troubleshooting guide, otherwise, let us know.

5 - Connect the web app to the database

With the web app and PostgreSQL database created, the next step is to connect the web app to the PostgreSQL database in Azure.

The web app code uses database information in four environment variables named,and to connect to the PostgresSQL server.

InstructionsScreenshot
In the portal, go to the App Service page for the web app.
  1. Select Configuration under Settings on the left side.

  2. Select Application settings at the top of the page.

A screenshot showing how to navigate to App Settings in the Azure portal.
Create application settings:
  1. Select + New application setting to create settings for each of the following values (which are expected by the django sample app):

    • DBHOST → Use the server name you used earlier when created the database, for example, msdocs-python-postgres-webapp-db-<unique id>. The code in azuresite/sprers.eu automatically appends sprers.eu to create the full PostgreSQL server URL.
    • DBNAME → Enterthe name of the application database.
    • DBUSER → The administrator user name used when you provisioned the database.
    • DBPASS → The administrator secure password you created earlier.
  2. Confirm you have four settings and view their hidden values.

  3. Select Save and to apply the settings.

A screenshot showing how to configure the App Settings in the Azure portal.

To configure environment variables for the web app from VS Code, you must have the Azure Tools extension pack installed and be signed into Azure from VS Code.

InstructionsScreenshot
Locate the Azure icon in the left-hand toolbar and select it to bring up the Azure Tools for VS Code extension.A screenshot showing how to locate the Azure Tools extension in VS Code.
In the Azure Tools extension:
  1. Expand RESOURCES. (Make sure resources are sorted by resource type.)

  2. Locate your web app, expand its node, and right-click Application Settings to bring up the context menu.

  3. Select Add new setting from the menu.

A screenshot showing how to add a setting <a href=nokia 5800 certificate error contact the supplier the App Service in VS Code.">
In the dialog box at the top of the VS Code window, add each setting name followed by its sprers.eu the following settings:
  • DBHOST → Enter the server name you used earlier when created the database, for example, msdocs-python-postgres-webapp-db-<unique-id>. The code in azuresite/sprers.eu automatically appends to create the full PostgreSQL server URL.
  • DBNAME → Enter restaurant.
  • DBUSER → Enter the administrator user name you specified when creating the database. The code in azuresite/sprers.eu automatically constructs the full Postgres username from andso don't include the portion.
  • DBPASS → Enter the administrator password you specified when creating the database. The code in azuresite/sprers.eu automatically constructs the full Postgres username from andso don't include the portion.
A screenshot showing adding setting name for app service to connect to PostgreSQL database in VS Code.A screenshot showing adding setting value for app service to connect to PostgreSQL database in VS Code.

To set environment variables in App Service, you create app settings with the following az webapp config appsettings set command.

  • DBHOST → Use the name of the name you used earlier with the command. The code in azuresite/sprers.eu automatically appends to create the full PostgreSQL server URL.
  • DBNAME → Use .
  • DBUSER, DBPASS → Use the administrator credentials that you used with the earlier command. The code in azuresite/sprers.eu automatically constructs the full Postgres username from anddjango file upload keyerror don't include the portion.

Having issues? Refer first to the Troubleshooting guide, otherwise, let us know.

6 - Deploy your application code to Azure

Azure App service supports multiple methods to deploy your application code to Azure including support for GitHub Actions and all major CI/CD tools. This article focuses on how to deploy your code from your local workstation to Azure.

To deploy a web app from VS Code, you must have the Azure Tools extension pack installed and be signed into Azure from VS Code.

You can deploy your application code from a local Git repository to Azure by configuring a Git remote in your local repo pointing at Azure to push code to. The URL of the remote repository and Git credentials needed for configuration can be retrieved using either the Azure dj skinhead-extreme terror or the Azure CLI.

InstructionsScreenshot
Navigate to the App Service for your application.
  1. Enter the name of your App Service in the search box at the top of the screen.

  2. The App Service will appear under the Resources heading. Select the App Service to navigate to it.

A screenshot showing how <a href=unknown bios error error code = 8302 locate your App Service using the search toolbar at the top of the Azure portal.">
Go to the page for the App Service.
  1. Select Deployment Center from the menu on the left side of the screen.

  2. In the dropdown list labeled Source, select Local Git.

  3. Select Save from the top menu bar.

A screenshot showing how to navigate to the deployment center in App Service and select Local Git as the deployment method in the Azure portal.
After saving, the page will refresh and display the address for the remote Git repository.

Copy the value of the Git Clone Uri as this value will be used to set up a Git remote in a later step.
A screenshot showing the deployment center after saving and the remote Git URL to use for deployments in the Azure portal.
Go to the Deployment Center page, django file upload keyerror.
  1. Navigate to the Local Git/FTPS credentials tab.

  2. Locate the username and password under the Application Scope credentials.

  3. Keep this screen open so you can copy these credentials momentarily when you deploy your code to the remote repository.

When you push code to the remote Git repository for the first time, these credentials are needed to authenticate django file upload keyerror the remote repository.
A screenshot showing the location of the deployment credentials in the deployment center for an App Service in the Azure portal.

First, you need to tell Azure what branch to use for deployment. This value is stored in the app settings for the web app with a key of. For this example, you will be deploying code from the branch.

Next, django file upload keyerror, configure the deployment source for your web app to be local Git using the command. This command will output the URL of the remote Git repository that you will be pushing code to. Make a copy of this value as you will need it in a later step.

Retrieve the deployment credentials for your application. These will be needed for Git to authenticate to Azure when you push code to Azure in a later step.

Next, in the root directory of your application, configure a Git remote that points to Azure using the Git URL of the Azure remote obtained in a previous step.

You can now push code from your local Git repository to Azure using the Git remote you configured.

The first time you push code to Azure, Git will prompt you for the Azure deployment credentials you obtained in a previous step. Git will then cache these credentials so you won't have to enter them on subsequent deployments.

Applications can be deployed to Azure by creating and uploading a ZIP file of the application code to Azure. ZIP files can be uploaded to Azure using the Azure CLI or a HTTP client like cURL.

Enable build automation

When deploying a ZIP file of your Python code, you need to set a flag to enable Azure's build automation. The build automation will install any necessary requirements and package the application to run on Azure.

Build automation in Azure is enabled by setting the app setting in either the Azure portal or Azure CLI.

InstructionsScreenshot
Step 1. On the page for the web app in the Azure portal:
  • Select Configuration under the Settings header in the left toolbar to bring up the Application settings.
  • Select New application setting under Application settings.
A screenshot showing the app settings for a web app and how to add a new setting in the Azure portal.
Step 2. Using the dialog, enter a new setting with:
  • NameSCM_DO_BUILD_DURING_DEPLOYMENT
  • Valuetrue
A screenshot showing the dialog box used to add an app settings in the Azure portal.
Step 3. Select the Save button to save your settings.A screenshot showing the location of the save button in the Application settings page for an App Service in the Azure portal.

Create a ZIP file of your application

Next, create a ZIP file of your application. You only need to include components of the application itself. You do not need to include any files or directories that start with a dot () such as,or .

On macOS or Linux, django file upload keyerror, you can use the built in utility to create a ZIP file.

Upload the ZIP file to Azure

Once you have a ZIP file, the file can be uploaded to Azure using either Azure CLI or an HTTP client.

To use an Django file upload keyerror client such as cURL to upload your ZIP file to Azure, you need the deployment username and password for your App Service. These credentials can be obtained from the Azure portal.

  1. On the page for the web app, select Deployment center from the resource menu on the left side of the page.
  2. Select the FTPS credentials tab.
  3. The Username and Password are shown under the Application scope heading. For ZIP file deployments, only use the part of the username after the character that starts with afor example. These credentials will be needed in the cURL command below.

A screenshot showing the location of the deployment credentials in the Azure portal.

Run the following command to upload your zip file to Azure and deploy your application. The username is the deployment username obtained above. When this command is run, you will be prompted for the deployment password.

Having issues? Refer first to the Troubleshooting guide, otherwise, let us know.

7 - Migrate app database

With the code deployed and the database in place, the app is almost ready to use. First, you need to establish the necessary schema in the database itself. You do this by "migrating" the data models in the Django app to the database.

Step 1. Create SSH session and connect to web app server.

Navigate to page for the App Service instance in the Azure portal.

  1. Select SSH, under Development Tools on the left side
  2. Then Go to open an SSH console on the web app server. (It may take a minute to connect for the first time as the web app container needs to start.)

In VS Code, you can use the Azure Tools extension pack, django file upload keyerror, which must be installed and be signed into Azure from VS Code.

In the App Service section of the Azure Tools extension:

  1. Locate your web app and right-click to bring up the context menu.
  2. Select SSH into Web App to open an SSH terminal window.

Run to open an SSH session for the web app in the browser:

Note

If you cannot connect to the SSH session, then the app itself has failed to start. Check the diagnostic logs for details, django file upload keyerror. For example, django file upload keyerror, if you centos 6.2 kernell error created the necessary app settings in the previous section, the logs will indicate .

Step 2. In the SSH session, run the following command to migrate the models into the database schema (you can paste commands using Ctrl+Shift+V):

When you deploy the Flask sample app to Azure App Service, the database tables are created automatically in Azure PostgreSQL, django file upload keyerror. If the tables aren't created, try the following command:

If you encounter any errors related to connecting to the database, check the values of the application settings of the App Service created in the previous section, namely,django file upload keyerror, and. Without those settings, the migrate command can't communicate with the database.

Tip

In an SSH session, for Django you can also create users with the command like you would with a typical Django app. For more information, django file upload keyerror, see the documentation for django django-admin and sprers.eu Use the superuser account to access the portion of the web site. For Flask, use an extension such as Flask-admin to provide the same functionality.

Having issues? Let us know.

8 - Django file upload keyerror to the app

Browse to the deployed application in your web browser at the URL. It can take a minute or two for the app to start, so if you see a default app page, django file upload keyerror, wait a minute and refresh the browser.

When you see your sample web app, it's running in a Linux container in App Django file upload keyerror using a built-in image Congratulations! You've deployed your Python app to App Service.

A screenshot of the <i>Django file upload keyerror</i> web app with PostgreSQL running in Azure showing restaurants and restaurant reviews.

A screenshot of the Django web app with PostgreSQL running in Azure showing restaurants and restaurant reviews.

Having issues? Let us know.

9 - Stream diagnostic logs

Azure App Service captures all messages output to the console to help you diagnose issues with your application. The sample app includes statements to demonstrate this capability as shown below.

You can access the console logs generated from inside the container that hosts the app on Azure.

InstructionsScreenshot
First, you need to enable streaming logs in Azure App Service. Navigate to page for the App Service instance in the Azure portal.
  1. Select the App Service logs under the Monitoring heading in the menu on the left side of the page.

  2. Change the Application Logging property from Off to File System.

  3. Enter a retention period of 30 days for the logs.

  4. Select Save to save your changes.

A screenshot showing how to set application logging in the Azure portal.
Select the Log stream item from the menu under the Monitoring section. Refresh the home page in the app or attempt other requests to generate some log messages.

You will see any log messages generated by your app and messages generated by the service in the output.
A screenshot showing how to stream logs in the Azure portal.
InstructionsScreenshot
First, you need to enable streaming logs in Azure App Service.

In the App Service section of the Azure Tools for VS Code extension, right-click on your App Service instance and select Start Streaming Logs from the menu.
A screenshot showing how to set application logging in VS Code.
The console logs appear in VS Code's Output window. Refresh the home page in the app or attempt other requests to generate some log messages.

You'll see any log messages generated by your app and other messages generated by the service in the output.
django file upload keyerror screenshot showing VS Code output window.">

Run the following Azure CLI commands to see the log stream. This command uses parameters cached in the .azure/config file.

Step 1. Configure Azure App Service to output logs to the App Service filesystem using the az webapp log config command.

Step 2. To stream logs, use the az webapp log tail command.

Step 3. Refresh the home page in the app or attempt other requests to generate some log messages. The output should look similar to the following.

Having issues? Let us know.

Clean up resources

You can leave the app and database running as long as you want for further development work and skip ahead to Next steps.

However, when you're finished with the sample app, you can remove all of the resources for the app from Azure to ensure you don't incur other charges and keep your Azure subscription uncluttered. Removing the resource group also removes all resources in the resource group and is the fastest way to remove all Azure resources for your app.

Follow these steps while signed-in to the Azure portal to delete a resource group.

InstructionsScreenshot
Navigate to the resource group in the Azure portal.
  1. Enter the name of the resource group in the search bar at the top of the page.
  2. Under the Resource Groups heading, select the name of the resource group to navigate to it.
A screenshot showing how to find resource group in the Azure portal.
Select the Delete resource group button at the top of the page.A screenshot showing how to delete a resource group in the Azure portal.
In the confirmation dialog, enter the name of the resource group to confirm deletion. Select Delete to delete the resource group.
InstructionsScreenshot
In the Azure Tools extension for VS Code:
  1. Locate the section named RESOURCE GROUPS and right-click on the name of the resource group you want to delete.
  2. Select Delete from the menu.
A screenshot showing how to delete a resource group in VS Code.
Enter the name of the resource group in the dialog box to confirm deletion of the resource group.A screenshot showing how to finish deleting a resource in VS Code.

Delete the resource group by using the az group delete command.

You can optionally add the argument to allow the command to return before the operation is complete.

Having issues? Let us know.

Next steps

Learn how to map a custom DNS name to your app:

Learn how App Service runs a Python app:

Similar video

Multi Value Dict Key Error DJANGO

Django file upload keyerror - answer, matchless

"): _, created = sprers.eu_or_create( page=column[0], keyword=column[1], interval=column[2], email=column[3], billing=column[4], notes=column[5], ) context = {} return render(request, template, context)

I&#;m wondering why it&#;s returning the error

Tags: cv,django

You Might Also Like

Import Error cannot import name User Agent Mixing

Slow WIFI with Ubuntu LTS

Missing Modules (Cat /Proc/Modules ls /Dev) and UUID doesn&#;t exist in Busy Box

create a view for uploading a .csv file and parsing it on the template but it&#;s returning a

MultiValueDictKeyError at / 'file'

The template has

Then my views has

import csv, io from sprers.euuts import render from sprers.eub import messages def data_upload(request): template = "sprers.eu" if sprers.eu == 'GET': return render(request, template) csv_file = sprers.eu['file'] if not csv_sprers.euth('.csv'): sprers.eu(request, 'Please upload a .csv file.') data_set = csv_sprers.eu().decode('UTF-8') io_string = sprers.euIO(data_set) next(io_string) for column in sprers.eu(io_string, delimiter=',', quoteschar="

Issues

Uploading non-ascii filename causes error by UnicodeEncodeError.

If the form has two (or more) input fields for uploading files,
and if you fill in either field by non-ascii filename and the other
field empty, then an UnicodeEncodeError occurs when is_valid() is invoked.

To the contrary, no error occurs when
(1) the form has only one input field and fill it by non-ascii filename,
(2) or the form has two (or more) input fields and fill them all by filenames.
(3) or fill one or more input field(s) by ascii filename(s)

I wonder why the error occurs only on condition that
(4) the form has two (or more) input fields and one field is filled by
non-ascii filename and the other field(s) is/are kept empty.

[1] source code

[ sprers.eu ] class UploadForm(sprers.eu): attach_1 = sprers.eueld(required = False) attach_2 = sprers.eueld(required = False) def test_upload(self,request): if sprers.eu == 'POST': formup = UploadForm(sprers.eu,sprers.eu) if sprers.eu_valid(): result = sprers.eu_uploaded_file(sprers.eu) return HttpResponseRedirect('sprers.eu') * the form page is encoded in UTF [2] error message UnicodeEncodeError at /mysite1/debug/sprers.eu 'ascii' codec can't encode characters in position ordinal not in range() Unicode error hint The string that could not be encoded/decoded was: NON-ASCII-UPLOAD-FILENAME [3] traceback message Traceback: File "/usr/lib/python25/Lib/site-packages/django/core/handlers/sprers.eu" in get_response response = callback(request, *callback_args, **callback_kwargs) File "/mysite1/debug/sprers.eu" in upload return sprers.eu_upload(request) File "/mysite1/debug/util_mysite_sprers.eu" in test_upload if sprers.eu_valid(): File "/usr/lib/python25/Lib/site-packages/django/forms/sprers.eu" in is_valid return sprers.eu_bound and not bool(sprers.eu) File "/usr/lib/python25/Lib/site-packages/django/forms/sprers.eu" in _get_errors sprers.eu_clean() File "/usr/lib/python25/Lib/site-packages/django/forms/sprers.eu" in full_clean value = sprers.eu_from_datadict(sprers.eu, sprers.eu, sprers.eu_prefix(name)) File "/usr/lib/python25/Lib/site-packages/django/forms/sprers.eu" in value_from_datadict return sprers.eu(name, None) File "/usr/lib/python25/Lib/site-packages/django/utils/sprers.eu" in get val = self[key] File "/usr/lib/python25/Lib/site-packages/django/utils/sprers.eu" in __getitem__ raise MultiValueDictKeyError, "Key %r not found in %r" % (key, self) File "/usr/lib/python25/Lib/site-packages/django/utils/sprers.eu" in __repr__ super(MultiValueDict, self).__repr__()) Exception Type: UnicodeEncodeError at /mysite1/debug/sprers.eu Exception Value: 'ascii' codec can't encode characters in position ordinal not in range()

[FIXED] KeyError while reading a CSV file in Python

I am trying to plot the fall of an object (an optical fork to be precise) as a function of time in order to verify that the law of gravity is indeed The different data are supposed to represent the passage at each slot. The different slits are spaced 1 centimeter apart and there are 11 slits in all. I measured these data with an Arduino setup and I plot the graph and fit with Python. I have the data in a CSV file but when I run my code, I get an

I don't understand because the column T (s) is present in my DataFrame.

Here is my CSV File with name 'sprers.eu' (I specify that I don't want to select the first and last value of column T (i.e. and ) and that I don't want to read the Distance column):

T (s)Distance (m)

And here is my code:

Do you know where this error can come from?


Actually looking at the sprers.eu it seems that the separator,at least judging by the column name, is a semicolon. Also the column name should be "Time (s)". Please try:



Answered By - Jayvee
This Answer collected from stackoverflow and tested by PythonFixing community admins, is licensed under cc by-sa , cc by-sa and cc by-sa

Django Session KeyError

Guy NANA's profile photo

Guy NANA

unread,
Feb 25, , AM2/25/20

Reply to author

Sign in to reply to author

Forward

Sign in to forward

Delete

You do not have permission to delete messages in this group

Link

Report message as abuse

Sign in to report message as abuse

Show original message

Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message

to Django users

I have an angular frontend app which send file to django backend which data is setting in django session. After I send a httprequest to django backend to make ML tratements on that data and get the results. But I've a sever error: keyerror 'ts_dataset_copy': KeyError: 'ts_dataset_copy'
[24/Feb/ ] "GET /cv_classification/5/FOTS//None/0/0 HTTP/" Here are my django code:

Firstly I upload timeseries dataset file from angular frontend (All thing is ok)   


# second httrequest that throws a server internal error




Thanks for your help!
Pankaj Sharma's profile photo

Pankaj Sharma

unread,
Feb 25, , PM2/25/20

Reply to author

Sign in to reply to author

Forward

Sign in to forward

Delete

You do not have permission to delete messages in this group

Link

Report message as abuse

Sign in to report message as abuse

Show original message

Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message

to Django users

Make sure your line sprers.eun['ts_dataset_copy'], print anything above it, also make sure you are using POST method in forms (method = "post")

Guy NANA's profile photo

Guy NANA

unread,
Feb 25, , PM2/25/20

Reply to author

Sign in to reply to author

Forward

Sign in to forward

Delete

You do not have permission to delete messages in this group

Link

Report message as abuse

Sign in to report message as abuse

Show original message

Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message

to Django users

I don't understand the first part of your answer : Make sure your line sprers.eun['ts_dataset_copy'], print anything above it.

 For sending dataset file from angular app to django, I've used a post request.

The matter is that when I send the second http crosss-origin from angular app to my django app the previously session's elements that I've stored doesn't exist anymore. (I checked the session keys in the upload_local_dataset and receive In upload_local_dataset Session's keys : dict_keys(['ts_dataset', 'ts_dataset_copy']) but in the second views I received an empty dict In cv_classification Session's keys : dict_keys([]) so pandas' read_json throws an error ValueError: Invalid file path or buffer object type:

How can I save the state of session between two http cross-origin from angular app to django app ?
Juan Pablo Romero Bernal's profile photo

Juan Pablo Romero Bernal

unread,
Feb 26, , AM2/26/20

Reply to author

Sign in to reply to author

Forward

Sign in to forward

Delete

You do not have permission to delete messages in this group

Link

Report message as abuse

Sign in to report message as abuse

Show original message

Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message

to [email protected]

Guy NANA's profile photo

Guy NANA

unread,
Feb 26, , AM2/26/20

Reply to author

Sign in to reply to author

Forward

Sign in to forward

Delete

You do not have permission to delete messages in this group

Link

Report message as abuse

Sign in to report message as abuse

Show original message

Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message

to Django users

Hi!

Yes, it is.

INSTALLED_APPS = [
'sprers.eu',
'sprers.eu',
'sprers.euttypes',
'sprers.euns',
'sprers.eues',
'sprers.eufiles',
'sprers.euysisappConfig',

# Django Rest Framework - DRF
'rest_framework',
# Django Rest Pandas - DRP
'rest_pandas',

# CORS
'corsheaders',
]

MIDDLEWARE = [
# CORS
'sprers.euddleware',

'sprers.euMiddleware',
'sprers.eutyMiddleware',
'sprers.eunMiddleware',
'sprers.euewMiddleware',
'sprers.euticationMiddleware',
'sprers.eueMiddleware',
'sprers.euOptionsMiddleware',
]


Le mercredi 26 février UTC+1, juanblo a écrit :

Naveen Arora's profile photo

Naveen Arora

unread,
Feb 26, , AM2/26/20

Reply to author

Sign in to reply to author

Forward

Sign in to forward

Delete

You do not have permission to delete messages in this group

Link

Report message as abuse

Sign in to report message as abuse

Show original message

Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message

to Django users

Hi, 

please post the output of debugging the above, print after and before in these views and also check is something else is working using sprers.eun. 

@csrf_exempt
def upload_local_dataset(request):
if sprers.eu =='POST':
            dataset = sprers.eu_csv(sprers.eu('datasetfilepath'), header=None, index_col=None)
            sprers.eun['ts_datset']= sprers.eu_json(orient='values')

            print(sprers.eu_json(orient='values'))

            sprers.eun['ts_dataset_copy']= sprers.eu_json(orient='values')

            print(sprers.eun['ts_dataset_copy'])

returnHttpResponse(sprers.eu_json(orient='values'))
Post output of this plus the below one

def cv_classification(request, kfolds, dissimilarity_func, windows_length=0, noisy_law="", mu=0,std=0):
            noisy_law = noisy_sprers.eu()

            print(sprers.eun['ts_dataset_copy'])

            df = sprers.eu_json(sprers.eun['ts_dataset_copy'], orient='values')
            predictions = cv_classify(df, kfolds, dissimilarity_func, windows_length, noisy_law, mu, std)
returnJsonResponse(predictions, safe=False)

Guy NANA's profile photo

Guy NANA

unread,
Feb 26, , PM2/26/20

Reply to author

Sign in to reply to author

Forward

Sign in to forward

Delete

You do not have permission to delete messages in this group

Link

Report message as abuse

Sign in to report message as abuse

Show original message

Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message

to [email protected]


--
You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
To unsubscribe from this topic, visit sprers.eu
To unsubscribe from this group and all its topics, send an email to [email protected]
To view this discussion on the web visit sprers.eu%sprers.eu



--

Guy Rostan DJOUNANG  NANA

Élève Ingénieur en Informatique

-- Institut Africain d'Informatique
Certifié: LPIC-1 / OCA JAVA SE 8

Maîtrise de Mathématiques, Parcours type: Analyse - Algèbre - Géométrie

-- Faculté des Sciences / Université de Douala-Cameroun

Président du Comité des Étudiants de l'IAI

Juin - Octobre

LinkedIn: Guy Rostan DJOUNANG NANA (sprers.eu)

(+) / (+33) (0)

Guy NANA's profile photo

Guy NANA

unread,
Feb 26, , PM2/26/20

Reply to author

Sign in to reply to author

Forward

Sign in to forward

Delete

You do not have permission to delete messages in this group

Link

Report message as abuse

Sign in to report message as abuse

Show original message

Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message

to Django users

Le mercredi 26 février UTC+1, Naveen Arora a écrit :
Hi,


please
 post the output of debugging the above, print after and before in these
 views and also check is something else is working using
sprers.eun.

@csrf_exempt
    def upload_local_dataset(request):
        if sprers.eu == 'POST':
            dataset = sprers.eu_csv(sprers.eu('datasetfilepath'), header=None, index_col=None)
            sprers.eun['ts_datset'] = sprers.eu_json(orient='values')

            print(sprers.eu_json(orient='values'))


            sprers.eun['ts_dataset_copy'] = sprers.eu_json(orient='values')

            print(sprers.eun['ts_dataset_copy'])
            return HttpResponse(sprers.eu_json(orient='values'))


Post output of this plus the below one

def cv_classification(request, kfolds, dissimilarity_func, windows_length=0, noisy_law="", mu=0,std=0):


            noisy_law = noisy_sprers.eu()
            print(sprers.eun['ts_dataset_copy'])

            df = sprers.eu_json(sprers.eun['ts_dataset_copy'], orient='values')
            predictions = cv_classify(df, kfolds, dissimilarity_func, windows_length, noisy_law, mu, std)
            return JsonResponse(predictions, safe=False)


On Tuesday, 25 February UTC+, Guy NANA wrote:

Guy NANA's profile photo

Guy NANA

unread,
Feb 26, , PM2/26/20

Reply to author

Sign in to reply to author

Forward

Sign in to forward

Delete

You do not have permission to delete messages in this group

Link

Report message as abuse

Sign in to report message as abuse

Show original message

Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message

to [email protected]

Naveen Arora's profile photo

Naveen Arora

unread,
Feb 26, , PM2/26/20

Reply to author

Sign in to reply to author

Forward

Sign in to forward

Delete

You do not have permission to delete messages in this group

Link

Report message as abuse

Sign in to report message as abuse

Show original message

Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message

to Django users

Guy NANA's profile photo

Guy NANA

unread,
Feb 26, , PM2/26/20

Reply to author

Sign in to reply to author

Forward

Sign in to forward

Delete

You do not have permission to delete messages in this group

Link

Report message as abuse

Sign in to report message as abuse

Show original message

Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message

to Django users

I checked sprers.eun for simple string (by adding sprers.eun['func_views'] = 'upload_local_dataset' in the upload_local_dataset view) but it is always have an empty sprers.eun in the second view.

Naveen Arora's profile photo

Naveen Arora

unread,
Feb 27, , AM2/27/20

Reply to author

Sign in to reply to author

Forward

Sign in to forward

Delete

You do not have permission to delete messages in this group

Link

Report message as abuse

Sign in to report message as abuse

Show original message

Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message

to Django users

Deploy a Python (Django or Flask) web app with PostgreSQL in Azure

  • Article
  • 33 minutes to read

In this tutorial, you'll deploy a data-driven Python web app (Django or Flask) with the Azure Database for PostgreSQL relational database service. The Python app is hosted in a fully managed Azure App Service which supports Python or higher in a Linux server environment. You can start with a basic pricing tier that can be scaled up at any later time.

An architecture diagram showing an App Service with a PostgreSQL database in Azure.

To complete this tutorial, you'll need:

1 - Sample application

Sample Python applications using the Flask and Django framework are provided to help you follow along with this tutorial. Download or clone one of the sample applications to your local workstation.

To run the application locally, navigate into the application folder:

Create a virtual environment for the app:

Install the dependencies:

Note

If you are following along with this tutorial with your own app, look at the sprers.eu file description in each project's sprers.eu file (Flask, Django) to see what packages you'll need.

This sample application requires an .env file describing how to connect to your local PostgreSQL instance. Create an .env file as shown below using the sprers.eu file as a guide. Set the value of to the name of an existing database in your local PostgreSQL instance. This tutorial assumes the database name is restaurant. Set the values of , , and as appropriate for your local PostgreSQL instance.

For Django, you can use SQLite locally instead of PostgreSQL by following the instructions in the comments of the sprers.eu file.

Create the and database tables:

Run the app:

In a web browser, go to the sample application at and add some restaurants and restaurant reviews to see how the app works.

A screenshot of the Flask web app with PostgreSQL running locally showing restaurants and restaurant reviews.

In a web browser, go to the sample application at and add some restaurants and restaurant reviews to see how the app works.

A screenshot of the Django web app with PostgreSQL running locally showing restaurants and restaurant reviews.

Tip

With Django, you can create users with the command like you would with a typical Django app. For more information, see the documentation for django django-admin and sprers.eu Use the superuser account to access the portion of the web site. For Flask, use an extension such as Flask-admin to provide the same functionality.

Having issues? Let us know.

2 - Create a web app in Azure

To host your application in Azure, you need to create Azure App Service web app.

Sign in to the Azure portal and follow these steps to create your Azure App Service resource.

InstructionsScreenshot
In the Azure portal:
  1. Enter app services in the search bar at the top of the Azure portal.

  2. Select the item labeled App Services under the under Services heading on the menu that appears below the search bar.

A screenshot showing how to use the search box in the top tool bar to find App Services in Azure portal.
On the App Services page, select + Create.A screenshot showing the location of the Create button on the App Services page in the Azure portal.
On the Create Web App page, fill out the form as follows:
  1. Resource Group → Select Create new and use a name of msdocs-python-postgres-webapp-rg.

  2. Name → Use msdocs-python-postgres-webapp-<unique-id>. The name must be unique across Azure with the web app's URL ).

  3. Runtime stackPython

  4. Region → Any Azure region near you.

  5. App Service Plan → Select Create new under Linux Plan and use the name of msdocs-python-postgres-webapp-plan.

  6. App Service Plan → Select Change size under Sku and size to select a different App Service plan.

A screenshot showing how to fill out the form to create a new App Service in the Azure portal.
In the Spec Picker section, select an App Service plan. The App Service plan controls how many resources (CPU/memory) are available to your app and the cost of those resources.
  1. Select Dev/Test.

  2. Select B1 (Basic) Plan.

    The B1 Basic plan will incur a small charge against your Azure account but is recommended for better performance over the F1 (Free) plan.

  3. Select Apply.

A screenshot showing how to select the basic App Service plan in the Azure portal.
Back on the Create Web App page, select the Review + create button at the bottom of the screen.

This will take you to a page to review the configuration. Select Create to create your App Service.
A screenshot showing the location of the Review plus Create button in the Azure portal.

To create Azure resources in VS Code, you must have the Azure Tools extension pack installed and be signed into Azure from VS Code.

InstructionsScreenshot
Locate the Azure icon in the left-hand toolbar and select it to bring up the Azure Tools for VS Code extension.

If you do not see the Azure tools icon, make sure you have the Azure Tools extension for VS Code installed.
A screenshot showing how to find the VS Code Azure extension in VS Code.
In the Azure Tools extension:
  1. Expand RESOURCES and find your subscription. (Make sure resources are grouped by resource type.)

  2. Right-click App Services in your subscription.

  3. Select Create New Web App(Advanced).

A screenshot showing how to create a new web app in VS Code.
In the dialog box at the top of the screen, enter the name of msdocs-python-postgresql-webapp-<unique-id> for this web app.

The name must be unique across Azure. When deployed, this name is used in the DNS name of the web app is .
A screenshot showing how to use the search box in the top tool bar of VS Code to name a new web app.
Select Create New Resource Group and enter msdocs-python-postgres-webapp-rg in the prompt, if the resource group does not already exist.A screenshot showing how to use the search box in the top tool bar of VS Code to create a new resource group.A screenshot showing how to use the search box in the top tool bar of VS Code to name a new resource group.
Select the runtime stack for the application. For this example, select Python .A screenshot showing how to use the search box in the top tool bar of VS Code to set the runtime stack of a web app in Azure.
Select a region/location near you, such as .A screenshot showing how to use the search box in the top tool bar of VS Code to set location for new web app resource in Azure.
Configure Linux App Service Plan:
  1. Select Create new App Service plan.

  2. Enter msdocs-python-postgres-webapp-plan or use the auto-generated name.

A screenshot showing how to use the search box in the top tool bar of VS Code to create a new App Service plan in Azure.A screenshot showing how to use the search box in the top tool bar in VS Code to name a new App Service plan in Azure.
Select the App Service plan pricing tier for this web app.

The App Service plan controls how many resources (CPU/memory) are available to your app and how much you pay. For this example, it's recommended to select the Basic (B1) Develop and test pricing tier. This will incur a small cost in your Azure subscription but provides better performance than the Free (F1) tier.
A screenshot showing how to use the search box in the top tool bar in VS Code to select a pricing tier for a web app in Azure.
Skip adding Application Insights to your web app by selecting Skip for now.

After the last choice, the Azure starts to create the app service.
A screenshot showing how to use the search box in the top tool bar of VS Code to skip configuring Application Insights for a web app in Azure.
View the output and browse to the website:
  1. When a message appears indicating that the new App Service was created, select View Output to switch to the Output window in VS Code.

  2. To confirm that the App Service is running properly, right-click the App Service name, and select Browse Website.

  3. Because you haven't deployed your own code to the App Service yet (which you do in a later step), only a default app page appears.

A screenshot showing deployment with Visual Studio Code and View Output Button.A screenshot showing deployment with Visual Studio Code and how to view App Service in Azure portal.A screenshot showing the default App Service web page when no app has been deployed.

Azure CLI commands can be run in the Azure Cloud Shell or on a workstation with the Azure CLI installed.

Step 1. Create a resource group using the az group create command. A resource group will act as a container for all of the Azure resources related to this application.

  • location → A location near you, for example . Use to list locations.
  • name → You will use this resource group to organize all the Azure resources needed to complete this tutorial. (for example, )

Step 2. Create an App Service plan using the az appservice plan create command.

  • name → Name for the Azure Web App plan,
  • resource-group → Use the same resource group name you used when you created the web app, for example .
  • sku → Defines the size (CPU, memory) and cost of the app service plan. This example uses the B1 (Basic) service plan, which will incur a small cost in your Azure subscription. For a full list of App Service plans, view the App Service pricing page.
  • is-linux → Selects Linux as the host operating system.

Step 3. Create the App Service web app using the az webapp create command.

  • name → The app service name is used as both the name of the resource in Azure and to form the fully qualified domain name for your app in the form of the server endpoint . This name must be unique across all Azure and the only allowed characters are -, -, and . For example, use where is any three characters.
  • runtime → The runtime specifies what version of Python your app is running. This example uses Python . To list all available runtimes, use the command .
  • plan → Use the same app service plan name from Step 2. ()
  • resource-group → Use the same resource group name from Step 1. ()

Note

This tutorial shows step-by-step use of Azure CLI commands to reinforce the logical steps that go into creating and deploying an App Service. Once you get familiar with the steps, you can try the that creates a webapp and deploys its code from a local workspace to App Service.

Having issues? Refer first to the Troubleshooting guide, otherwise, let us know.

3 - Create the PostgreSQL database in Azure

You can create a PostgreSQL database in Azure using the Azure portal, Visual Studio Code, or the Azure CLI.

Sign in to the Azure portal and follow these steps to create your Azure Database for PostgreSQL resource.

InstructionsScreenshot
In the Azure portal:
  1. Enter postgres in the search bar at the top of the Azure portal.

  2. Select the item labeled Azure Database for PostgreSQL flexible servers under the under Services heading on the menu that appears below the search bar.

A screenshot showing how to use the search box in the top tool bar to find Postgres Services in the Azure portal.
On the Azure Database for PostgreSQL flexible servers page, select + CreateA screenshot showing the location of the Create button on the Azure Database for PostgreSQL servers page in the Azure portal.
On the next page, select Create under Flexible server.A screenshot showing the location of the Create Flexible Server button on the Azure Database for PostgreSQL deployment option page in the Azure portal.
On the Flexible server page, fill out the form as follows:
  1. Resource group → Select and use a name of msdocs-python-postgres-webapp-rg.

  2. Server name → Enter a name such as msdocs-python-postgres-webapp-db-<unique-id>. The name must be unique across Azure with the database server's URL ). Allowed characters are -, -, and .

  3. Region → Same Azure region used for the Web App.

  4. Data sourceNone

  5. Workload typeProduction

  6. Compute + storage → Select Configure server to select a different Compute + storage plan, which is discussed below.

  7. Availability zone → Keep the default (which is no preference).

  8. Version → Keep the default (which is the latest version).

A screenshot showing how to fill out the form to create a new Azure Database for PostgreSQL in the Azure portal.
On the Compute + storage page, continue configuring the flexible server:
  1. Compute tier → Select Burstable.

  2. Compute size → Select Standard_B1ms.

  3. Select Save to return to the main configuration page.

A screenshot showing how to select and configure the basic database service plan in the Azure portal.
Back on the main Flexible server page, finish the basic configuration:
  1. Administrator account → Enter a Admin username and Password to be used for the database administrator account.

  2. Select Next: Networking at the bottom of the screen.

Creating administrator account information for the PostgreSQL Flexible server in the Azure portal.
On the Networking page, add a firewall rule that allows your local environment to access the database server:
  1. Select Add current client IP address to allow access from your local environment.

  2. Select Review + Create at the bottom of the screen.

    This will take you to the Review page. Select Create to create your Azure Database for PostgreSQL Flexible Server Service.

A screenshot showing adding current IP as a firewall rule for the PostgreSQL Flexible server in the Azure portal.

In your local environment using the PostgreSQL interactive terminal psql, connect to the PostgreSQL database server, and create the database:

The values of and are the values from a previous step. If you have trouble connecting, restart the database and try again.

Optionally, verify that the database was successfully created by running to change the prompt from (default) to the . Type to show help or to quit.

Follow these steps to create your Azure Database for PostgreSQL resource using the Azure Tools extension pack in Visual Studio Code.

InstructionsScreenshot
In Visual Studio Code, select the Azure Tools extension. Sign into Azure, if you haven't already.A screenshot showing how to open Azure Extension for Database in VS Code.
In the Azure Tools extension:
  1. Expand RESOURCES. (Make sure resources are sorted by resource type.)

  2. Under your subscription, right-click PostgresSQL servers (Flexible) and select Create Server.

A screenshot showing how create a database server in VSCode.
Select PostgreSQL Flexible Server from the list.A screenshot how to create a new resource in VS Code.
In the VS Code prompts, enter the following information:
  1. Server name → Enter a name for the database server that's unique across all Azure (the database server's URL becomes ). Allowed characters are -, -, and . For example: msdocs-python-postgres-webapp-db-<unique-id>.

  2. Select the Postgres SKU and options → Select B1ms Basic, 1 vCore, 2GiB Memory, 32GB storage.

  3. Administrator Username and Administrator Password → Enter credentials for an administrator account on the database server. Record these credentials as you'll need them later in this tutorial.

  4. Select a resource group → Select the resource group you created the App Service in, for example msdocs-python-postgres-webapp-rg.

  5. Select a location → Select the same location as the App Service.

A screenshot showing how to create a new resource in the VS Code - server name.A screenshot showing how to create a new resource in VS Code - SKU.A screenshot showing how to create a new resource in VS Code - admin account name.A screenshot showing how to create a new resource in VS Code - admin account password.A screenshot showing how to create a new resource in VS Code - resource group.A screenshot showing how to create a new resource in VS Code - location.
Once the database is created, configure access from your local environment to the PostgreSQL database server:
  1. Open the Command Palette (Ctrl + Shift + P).

  2. Search for select PostgreSQL: Configure Firewall.

  3. Select a subscription if prompted.

  4. Select the database you created above, for example msdocs-python-postgres-webapp-db-<unique-id>. If the database name doesn't appear in the list, it's likely it hasn't finished being created.

  5. Select Yes in the dialog box to add your IP address to the firewall rules of the PostgreSQL server.

A screenshot showing how to configure access for a database by configuring a firewall rule in VS Code.A screenshot showing how to select the correct PostgreSQL server to add a firewall rule in VS Code.A screenshot showing a dialog box asking to add firewall rule for local IP address in VS Code.
After the firewall rule allowing local access has been successfully added, create the database.
  1. Select Azure icon the activity bar.

  2. Select Databases.

  3. Under your subscription, find the PostgreSQL Server you created (for example, msdocs-python-postgres-webapp-db-<unique-id>), right-click and select Create Database.

  4. Enter restaurant as the Database Name.

If you have trouble creating the database, the server may still be processing the firewall rule from the previous step. Wait a moment and try again.
A screenshot showing how to create a PostgreSQL database server in VS Code.

Run to sign in to and follow these steps to create your Azure Database for PostgreSQL resource.

Step 1. Run the az postgres flexible-server create command to create the PostgreSQL server and database in Azure using the values below. It is not uncommon for this command to run for a few minutes to complete.

  • resource-group → Use the same resource group name in which you created the web app, for example .

  • name → The PostgreSQL database server name. This name must be unique across all Azure (the server endpoint becomes ). Allowed characters are -, -, and . A good pattern is to use a combination of your company name and server identifier. ()

  • location → Use the same location used for the web app.

  • admin-user → Username for the administrator account. It can't be , , , , , or . For example, is okay.

  • admin-password Password of the administrator user. It must contain 8 to characters from three of the following categories: English uppercase letters, English lowercase letters, numbers, and non-alphanumeric characters.

    Important

    When creating usernames or passwords do not use the character. Later you create environment variables with these values where the character has special meaning within the Linux container used to run Python apps.

  • public-access → which sets the server in public access mode with no firewall rules. Rules will be created in a later step.

  • sku-name → The name of the pricing tier and compute configuration, for example . Follow the convention {pricing tier}{compute generation}{vCores} set create this variable. For more information, see Azure Database for PostgreSQL pricing.

  • tier

Step 2. Configure the firewall rules on your server by using the az postgres flexible-server firewall-rule create command to give your local environment access to connect to the server.

  • resource-group → Use the same resource group name in which you created the web app, for example .
  • name → The PostgreSQL database server name.
  • rule-nameAllowMyIP.
  • start-ip-address → equal to your IP address. To get your current IP address, see sprers.eu
  • end-ip-address → equal to start-ip-address.

Step 3. (optional) You can retrieve connection information using the az postgres server show. The command outputs a JSON object that contains connection strings for the database along and the name.

  • resource-group → The name of resource group you used, for example, msdocs-python-postgres-webapp-rg.
  • name → The name of the database server, for example, msdocs-python-postgres-webapp-db-<unique-id>.

Step 4. In your local environment using the PostgreSQL interactive terminal psql, connect to the PostgreSQL database server, and create the database.

The values of and are the values from a previous step. If you have trouble connecting, restart the database and try again.

Step 5.(optional) Verify database was successfully created by running to change the prompt from (default) to .

Type to show help or to quit.

Having issues? Let us know.

4 - Allow web app to access the database

After the Azure Database for PostgreSQL server is created, configure access to the server from the web app by adding a firewall rule. This can be done through the Azure portal or the Azure CLI.

If you're working in VS Code, right-click the database server and select Open in Portal to go to the Azure portal. Or, go to the Azure Cloud Shell and run the Azure CLI commands.

InstructionsScreenshot
Add a rule to allow your web app to access the PostgreSQL Flexible server.
  1. In the left resource page for the server, select Networking.

  2. Select the checkbox next to Allow public access from any Azure service within Azure to this server.

  3. Select Save to save the change.

To further secure communication between production web apps and database servers, you should use an Azure Virtual Network.
A screenshot showing how to add access from other Azure services to a PostgreSQL database in the Azure portal.

Create a rule that allows other Azure services to connect to the PostgreSQL server by using the az postgres server firewall-rule create command.

  • resource-group → Name of resource group from earlier in this tutorial. ()
  • server → Name of the server from Step 1. ()
  • name → Name for firewall rule. (use )
  • start-ip-address, end-ip-address → signals that access will be from other Azure services. This is sufficient for a demonstration app, but for a production app you should use an Azure Virtual Network.

Having issues? Refer first to the Troubleshooting guide, otherwise, let us know.

5 - Connect the web app to the database

With the web app and PostgreSQL database created, the next step is to connect the web app to the PostgreSQL database in Azure.

The web app code uses database information in four environment variables named , , , and to connect to the PostgresSQL server.

InstructionsScreenshot
In the portal, go to the App Service page for the web app.
  1. Select Configuration under Settings on the left side.

  2. Select Application settings at the top of the page.

A screenshot showing how to navigate to App Settings in the Azure portal.
Create application settings:
  1. Select + New application setting to create settings for each of the following values (which are expected by the django sample app):

    • DBHOST → Use the server name you used earlier when created the database, for example, msdocs-python-postgres-webapp-db-<unique id>. The code in azuresite/sprers.eu automatically appends sprers.eu to create the full PostgreSQL server URL.
    • DBNAME → Enter , the name of the application database.
    • DBUSER → The administrator user name used when you provisioned the database.
    • DBPASS → The administrator secure password you created earlier.
  2. Confirm you have four settings and view their hidden values.

  3. Select Save and to apply the settings.

A screenshot showing how to configure the App Settings in the Azure portal.

To configure environment variables for the web app from VS Code, you must have the Azure Tools extension pack installed and be signed into Azure from VS Code.

InstructionsScreenshot
Locate the Azure icon in the left-hand toolbar and select it to bring up the Azure Tools for VS Code extension.A screenshot showing how to locate the Azure Tools extension in VS Code.
In the Azure Tools extension:
  1. Expand RESOURCES. (Make sure resources are sorted by resource type.)

  2. Locate your web app, expand its node, and right-click Application Settings to bring up the context menu.

  3. Select Add new setting from the menu.

A screenshot showing how to add a setting to the App Service in VS Code.
In the dialog box at the top of the VS Code window, add each setting name followed by its sprers.eu the following settings:
  • DBHOST → Enter the server name you used earlier when created the database, for example, msdocs-python-postgres-webapp-db-<unique-id>. The code in azuresite/sprers.eu automatically appends to create the full PostgreSQL server URL.
  • DBNAME → Enter restaurant.
  • DBUSER → Enter the administrator user name you specified when creating the database. The code in azuresite/sprers.eu automatically constructs the full Postgres username from and , so don't include the portion.
  • DBPASS → Enter the administrator password you specified when creating the database. The code in azuresite/sprers.eu automatically constructs the full Postgres username from and , so don't include the portion.
A screenshot showing adding setting name for app service to connect to PostgreSQL database in VS Code.A screenshot showing adding setting value for app service to connect to PostgreSQL database in VS Code.

To set environment variables in App Service, you create app settings with the following az webapp config appsettings set command.

  • DBHOST → Use the name of the name you used earlier with the command. The code in azuresite/sprers.eu automatically appends to create the full PostgreSQL server URL.
  • DBNAME → Use .
  • DBUSER, DBPASS → Use the administrator credentials that you used with the earlier command. The code in azuresite/sprers.eu automatically constructs the full Postgres username from and , so don't include the portion.

Having issues? Refer first to the Troubleshooting guide, otherwise, let us know.

6 - Deploy your application code to Azure

Azure App service supports multiple methods to deploy your application code to Azure including support for GitHub Actions and all major CI/CD tools. This article focuses on how to deploy your code from your local workstation to Azure.

To deploy a web app from VS Code, you must have the Azure Tools extension pack installed and be signed into Azure from VS Code.

You can deploy your application code from a local Git repository to Azure by configuring a Git remote in your local repo pointing at Azure to push code to. The URL of the remote repository and Git credentials needed for configuration can be retrieved using either the Azure portal or the Azure CLI.

InstructionsScreenshot
Navigate to the App Service for your application.
  1. Enter the name of your App Service in the search box at the top of the screen.

  2. The App Service will appear under the Resources heading. Select the App Service to navigate to it.

A screenshot showing how to locate your App Service using the search toolbar at the top of the Azure portal.
Go to the page for the App Service.
  1. Select Deployment Center from the menu on the left side of the screen.

  2. In the dropdown list labeled Source, select Local Git.

  3. Select Save from the top menu bar.

A screenshot showing how to navigate to the deployment center in App Service and select Local Git as the deployment method in the Azure portal.
After saving, the page will refresh and display the address for the remote Git repository.

Copy the value of the Git Clone Uri as this value will be used to set up a Git remote in a later step.
A screenshot showing the deployment center after saving and the remote Git URL to use for deployments in the Azure portal.
Go to the Deployment Center page.
  1. Navigate to the Local Git/FTPS credentials tab.

  2. Locate the username and password under the Application Scope credentials.

  3. Keep this screen open so you can copy these credentials momentarily when you deploy your code to the remote repository.

When you push code to the remote Git repository for the first time, these credentials are needed to authenticate to the remote repository.
A screenshot showing the location of the deployment credentials in the deployment center for an App Service in the Azure portal.

First, you need to tell Azure what branch to use for deployment. This value is stored in the app settings for the web app with a key of . For this example, you will be deploying code from the branch.

Next, configure the deployment source for your web app to be local Git using the command. This command will output the URL of the remote Git repository that you will be pushing code to. Make a copy of this value as you will need it in a later step.

Retrieve the deployment credentials for your application. These will be needed for Git to authenticate to Azure when you push code to Azure in a later step.

Next, in the root directory of your application, configure a Git remote that points to Azure using the Git URL of the Azure remote obtained in a previous step.

You can now push code from your local Git repository to Azure using the Git remote you configured.

The first time you push code to Azure, Git will prompt you for the Azure deployment credentials you obtained in a previous step. Git will then cache these credentials so you won't have to enter them on subsequent deployments.

Applications can be deployed to Azure by creating and uploading a ZIP file of the application code to Azure. ZIP files can be uploaded to Azure using the Azure CLI or a HTTP client like cURL.

Enable build automation

When deploying a ZIP file of your Python code, you need to set a flag to enable Azure's build automation. The build automation will install any necessary requirements and package the application to run on Azure.

Build automation in Azure is enabled by setting the app setting in either the Azure portal or Azure CLI.

InstructionsScreenshot
Step 1. On the page for the web app in the Azure portal:
  • Select Configuration under the Settings header in the left toolbar to bring up the Application settings.
  • Select New application setting under Application settings.
A screenshot showing the app settings for a web app and how to add a new setting in the Azure portal.
Step 2. Using the dialog, enter a new setting with:
  • NameSCM_DO_BUILD_DURING_DEPLOYMENT
  • Valuetrue
A screenshot showing the dialog box used to add an app settings in the Azure portal.
Step 3. Select the Save button to save your settings.A screenshot showing the location of the save button in the Application settings page for an App Service in the Azure portal.

Create a ZIP file of your application

Next, create a ZIP file of your application. You only need to include components of the application itself. You do not need to include any files or directories that start with a dot () such as , , , or .

On macOS or Linux, you can use the built in utility to create a ZIP file.

Upload the ZIP file to Azure

Once you have a ZIP file, the file can be uploaded to Azure using either Azure CLI or an HTTP client.

To use an HTTP client such as cURL to upload your ZIP file to Azure, you need the deployment username and password for your App Service. These credentials can be obtained from the Azure portal.

  1. On the page for the web app, select Deployment center from the resource menu on the left side of the page.
  2. Select the FTPS credentials tab.
  3. The Username and Password are shown under the Application scope heading. For ZIP file deployments, only use the part of the username after the character that starts with a , for example . These credentials will be needed in the cURL command below.

A screenshot showing the location of the deployment credentials in the Azure portal.

Run the following command to upload your zip file to Azure and deploy your application. The username is the deployment username obtained above. When this command is run, you will be prompted for the deployment password.

Having issues? Refer first to the Troubleshooting guide, otherwise, let us know.

7 - Migrate app database

With the code deployed and the database in place, the app is almost ready to use. First, you need to establish the necessary schema in the database itself. You do this by "migrating" the data models in the Django app to the database.

Step 1. Create SSH session and connect to web app server.

Navigate to page for the App Service instance in the Azure portal.

  1. Select SSH, under Development Tools on the left side
  2. Then Go to open an SSH console on the web app server. (It may take a minute to connect for the first time as the web app container needs to start.)

In VS Code, you can use the Azure Tools extension pack, which must be installed and be signed into Azure from VS Code.

In the App Service section of the Azure Tools extension:

  1. Locate your web app and right-click to bring up the context menu.
  2. Select SSH into Web App to open an SSH terminal window.

Run to open an SSH session for the web app in the browser:

Note

If you cannot connect to the SSH session, then the app itself has failed to start. Check the diagnostic logs for details. For example, if you haven't created the necessary app settings in the previous section, the logs will indicate .

Step 2. In the SSH session, run the following command to migrate the models into the database schema (you can paste commands using Ctrl+Shift+V):

When you deploy the Flask sample app to Azure App Service, the database tables are created automatically in Azure PostgreSQL. If the tables aren't created, try the following command:

If you encounter any errors related to connecting to the database, check the values of the application settings of the App Service created in the previous section, namely , , , and . Without those settings, the migrate command can't communicate with the database.

Tip

In an SSH session, for Django you can also create users with the command like you would with a typical Django app. For more information, see the documentation for django django-admin and sprers.eu Use the superuser account to access the portion of the web site. For Flask, use an extension such as Flask-admin to provide the same functionality.

Having issues? Let us know.

8 - Browse to the app

Browse to the deployed application in your web browser at the URL . It can take a minute or two for the app to start, so if you see a default app page, wait a minute and refresh the browser.

When you see your sample web app, it's running in a Linux container in App Service using a built-in image Congratulations! You've deployed your Python app to App Service.

A screenshot of the Flask web app with PostgreSQL running in Azure showing restaurants and restaurant reviews.

A screenshot of the Django web app with PostgreSQL running in Azure showing restaurants and restaurant reviews.

Having issues? Let us know.

9 - Stream diagnostic logs

Azure App Service captures all messages output to the console to help you diagnose issues with your application. The sample app includes statements to demonstrate this capability as shown below.

You can access the console logs generated from inside the container that hosts the app on Azure.

InstructionsScreenshot
First, you need to enable streaming logs in Azure App Service. Navigate to page for the App Service instance in the Azure portal.
  1. Select the App Service logs under the Monitoring heading in the menu on the left side of the page.

  2. Change the Application Logging property from Off to File System.

  3. Enter a retention period of 30 days for the logs.

  4. Select Save to save your changes.

A screenshot showing how to set application logging in the Azure portal.
Select the Log stream item from the menu under the Monitoring section. Refresh the home page in the app or attempt other requests to generate some log messages.

You will see any log messages generated by your app and messages generated by the service in the output.
A screenshot showing how to stream logs in the Azure portal.
InstructionsScreenshot
First, you need to enable streaming logs in Azure App Service.

In the App Service section of the Azure Tools for VS Code extension, right-click on your App Service instance and select Start Streaming Logs from the menu.
A screenshot showing how to set application logging in VS Code.
The console logs appear in VS Code's Output window. Refresh the home page in the app or attempt other requests to generate some log messages.

You'll see any log messages generated by your app and other messages generated by the service in the output.
A screenshot showing VS Code output window.

Run the following Azure CLI commands to see the log stream. This command uses parameters cached in the .azure/config file.

Step 1. Configure Azure App Service to output logs to the App Service filesystem using the az webapp log config command.

Step 2. To stream logs, use the az webapp log tail command.

Step 3. Refresh the home page in the app or attempt other requests to generate some log messages. The output should look similar to the following.

Having issues? Let us know.

Clean up resources

You can leave the app and database running as long as you want for further development work and skip ahead to Next steps.

However, when you're finished with the sample app, you can remove all of the resources for the app from Azure to ensure you don't incur other charges and keep your Azure subscription uncluttered. Removing the resource group also removes all resources in the resource group and is the fastest way to remove all Azure resources for your app.

Follow these steps while signed-in to the Azure portal to delete a resource group.

InstructionsScreenshot
Navigate to the resource group in the Azure portal.
  1. Enter the name of the resource group in the search bar at the top of the page.
  2. Under the Resource Groups heading, select the name of the resource group to navigate to it.
A screenshot showing how to find resource group in the Azure portal.
Select the Delete resource group button at the top of the page.A screenshot showing how to delete a resource group in the Azure portal.
In the confirmation dialog, enter the name of the resource group to confirm deletion. Select Delete to delete the resource group.
InstructionsScreenshot
In the Azure Tools extension for VS Code:
  1. Locate the section named RESOURCE GROUPS and right-click on the name of the resource group you want to delete.
  2. Select Delete from the menu.
A screenshot showing how to delete a resource group in VS Code.
Enter the name of the resource group in the dialog box to confirm deletion of the resource group.A screenshot showing how to finish deleting a resource in VS Code.

Delete the resource group by using the az group delete command.

You can optionally add the argument to allow the command to return before the operation is complete.

Having issues? Let us know.

Next steps

Learn how to map a custom DNS name to your app:

Learn how App Service runs a Python app:

0 Comments

Leave a Comment