Skip to content

Commit 502bc6f

Browse files
committed
Merged main into live
2 parents 5cad7d3 + 48e5b62 commit 502bc6f

12 files changed

+274
-266
lines changed

docs/ide/quickstart-python.md

Lines changed: 33 additions & 33 deletions
Large diffs are not rendered by default.

docs/python/configure-web-apps-for-iis-windows.md

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
2-
title: Configure Python web apps for IIS
2+
title: Configure Python Web Apps for IIS
33
description: Configure Python web apps to run with Internet Information Services (IIS) from a Windows virtual machine by specifying settings in their web.config files.
4-
ms.date: 04/18/2024
4+
ms.date: 07/28/2025
55
ms.topic: how-to
66
author: cwebster-99
77
ms.author: cowebster
@@ -13,25 +13,25 @@ ms.subservice: python
1313

1414
# Configure Python web apps for IIS
1515

16-
When you use Internet Information Services (IIS) as a web server on a Windows computer (including [Windows virtual machines on Azure](/azure/architecture/reference-architectures/n-tier/windows-vm)), you need to configure the Python web application to enable IIS to properly process Python code. The configuration is accomplished through settings in the `web.config` file for the Python web app. This article describes how to configure the necessary settings.
16+
When you use Internet Information Services (IIS) as a web server on a Windows computer (including [Windows virtual machines on Azure](/azure/architecture/reference-architectures/n-tier/windows-vm)), you need to configure the Python web application to enable IIS to properly process Python code. The configuration is accomplished through settings in the *web.config* file for the Python web app. This article describes how to configure the necessary settings.
1717

1818
## Prerequisites
1919

20-
- Python on Windows installed. To run a web app, first install your required version of Python directly on the Windows host machine as described on [Install Python interpreters](installing-python-interpreters.md).
20+
- Python on Windows installed. To run a web app, first install your required version of Python directly on the Windows host machine as described in [Install Python interpreters](installing-python-interpreters.md).
2121

22-
- Identify the location of the `python.exe` interpreter. For convenience, you can add that location to your PATH environment variable.
22+
- Identify the location of the *python.exe* interpreter. For convenience, you can add that location to your PATH environment variable.
2323

2424
- Required packages installed. For a dedicated host, you can use the global Python environment to run your app rather than a virtual environment. Accordingly, you can install all of your app's requirements into the global environment by running the `pip install -r requirements.txt` command.
2525

2626
## Set web.config to point to the Python interpreter
2727

28-
The `web.config` file for your Python application instructs the IIS web server (version 7 or later) running on Windows about how it should handle Python requests through HttpPlatformHandler (recommended) or FastCGI. Visual Studio versions 2015 and earlier make these modifications automatically. For Visual Studio 2017 and later, you must modify the `web.config` file manually.
28+
The *web.config* file for your Python application instructs the IIS web server (version 7 or later) running on Windows about how it should handle Python requests through HttpPlatformHandler (recommended) or FastCGI. Visual Studio versions 2015 and earlier make these modifications automatically. For Visual Studio 2017 and later, you must modify the *web.config* file manually.
2929

30-
If your project does not already contain a `web.config` file, you can add one by right-clicking the project directory, selecting **Add > New Item** and searching for `web.config` or creating a blank `web.config` XML file.
30+
If your project doesn't already contain a *web.config* file, you can add one by right-clicking the project directory, selecting **Add > New Item** and searching for *web.config* or creating a blank *web.config* XML file.
3131

32-
### Option 1 : Configure the HttpPlatformHandler
32+
### Option 1: Configure the HttpPlatformHandler
3333

34-
The HttpPlatform module passes socket connections directly to a standalone Python process. This pass-through allows you to run any web server you like, but it requires a startup script that runs a local web server. This approach is commonly done by using a Python web framework, such as Flask or Django. You specify the script in the `<httpPlatform>` element of the `web.config` file. The `processPath` attribute points to the site extension's Python interpreter. The `arguments` attribute points to your startup script that runs a local web server, in this case `runserver.py`, and any arguments you want to provide:
34+
The HttpPlatform module passes socket connections directly to a standalone Python process. This pass-through allows you to run any web server you like, but it requires a startup script that runs a local web server. This approach is commonly done by using a Python web framework, such as Flask or Django. You specify the script in the `<httpPlatform>` element of the *web.config* file. The `processPath` attribute points to the site extension's Python interpreter. The `arguments` attribute points to your startup script that runs a local web server, in this case *runserver.py*, and any arguments you want to provide:
3535

3636
```xml
3737
<?xml version="1.0" encoding="utf-8"?>
@@ -56,18 +56,18 @@ The HttpPlatform module passes socket connections directly to a standalone Pytho
5656

5757
In this example, the `HTTP_PLATFORM_PORT` environment variable contains the port that your local server should listen on for connections from `localhost`. This example also shows how to create another environment variable, `SERVER_PORT`. You can create and assign environment variables as needed.
5858

59-
### Option 2 : Configure the FastCGI handler
59+
### Option 2: Configure the FastCGI handler
6060

61-
Alternatively, you can use FastCGI to configure your apps. FastCGI is an interface that works at the request level. IIS receives incoming connections and forwards each request to a WSGI app running in one or more persistent Python processes.
61+
Alternatively, you can use FastCGI to configure your apps. FastCGI is an interface that works at the request level. IIS receives incoming connections and forwards each request to a Web Server Gateway Interface (WSGI) app running in one or more persistent Python processes.
6262

6363
> [!NOTE]
64-
> Although you can set your project up using FastCGI, we recommend using **HttpPlatformHandler** to configure your apps, as the [WFastCGI](https://pypi.org/project/wfastcgi/) project is no longer maintained and may result in bugs.
64+
> Although you can set up your project using FastCGI, we recommend using **HttpPlatformHandler** to configure your apps because the [WFastCGI](https://pypi.org/project/wfastcgi/) project is no longer maintained and might result in bugs.
6565
6666
To use FastCGI, first install and configure the wfastcgi package as described in [pypi.org/project/wfastcgi/](https://pypi.io/project/wfastcgi).
6767

68-
Next, modify your application's `web.config` file to include the full paths to the `python.exe` executable and the `wfastcgi.py` file in the `PythonHandler` key. The following steps assume Python is installed in the *c:\python36-32* folder and the app code is in the *c:\home\site\wwwroot* folder. Adjust these values for your paths accordingly.
68+
Next, modify your application's *web.config* file to include the full paths to the *python.exe* executable and the *wfastcgi.py* file in the `PythonHandler` key. The following steps assume Python is installed in the *c:\python36-32* folder and the app code is in the *c:\home\site\wwwroot* folder. Adjust these values for your paths accordingly.
6969

70-
1. Modify the `PythonHandler` entry in the `web.config` file so the path matches the Python install location. For more information, see [IIS Configuration Reference](https://www.iis.net/configreference) (iis.net).
70+
1. Modify the `PythonHandler` entry in the *web.config* file so the path matches the Python install location. For more information, see [IIS Configuration Reference on iis.net](https://www.iis.net/configreference).
7171

7272
```xml
7373
<system.webServer>
@@ -79,7 +79,7 @@ Next, modify your application's `web.config` file to include the full paths to t
7979
</system.webServer>
8080
```
8181

82-
1. Within the `<appSettings>` section of the `web.config` file, add keys for `WSGI_HANDLER`, `WSGI_LOG` (optional), and `PYTHONPATH`:
82+
1. Within the `<appSettings>` section of the *web.config* file, add keys for `WSGI_HANDLER`, `WSGI_LOG` (optional), and `PYTHONPATH`:
8383

8484
```xml
8585
<appSettings>
@@ -96,25 +96,25 @@ Next, modify your application's `web.config` file to include the full paths to t
9696
- The `WSGI_HANDLER` key must point to a WSGI app importable from your app.
9797
- The `WSGI_LOG` key is optional, but the key is recommended for debugging your app.
9898

99-
1. Set the `WSGI_HANDLER` entry in the `web.config` file as appropriate for the framework you're using:
99+
1. Set the `WSGI_HANDLER` entry in the *web.config* file as appropriate for the framework you're using:
100100

101-
- **Bottle**: Add parentheses after the `app.wsgi_app` value as shown in this example. The parentheses are necessary because the object is a function rather than a variable. You can see the syntax in the `app.py` file.
101+
- **Bottle**: Add parentheses after the `app.wsgi_app` value as shown in this example. The parentheses are necessary because the object is a function rather than a variable. You can see the syntax in the *app.py* file.
102102

103103
```xml
104104
<!-- Bottle apps only -->
105105
<add key="WSGI_HANDLER" value="app.wsgi_app()"/>
106106
```
107107

108-
- **Flask**: Change the `WSGI_HANDLER` value to `<project_name>.app` where `<project_name>` matches the name of your project. You can find the exact identifier by looking at the `from <project_name> import app` statement in the `runserver.py` file. For example, if the project is named `FlaskAzurePublishExample`, the entry appears as follows:
108+
- **Flask**: Change the `WSGI_HANDLER` value to `<project_name>.app` where `<project_name>` matches the name of your project. You can find the exact identifier by looking at the `from <project_name> import app` statement in the *runserver.py* file. For example, if the project is named *FlaskAzurePublishExample*, the entry appears as follows:
109109

110110
```xml
111111
<!-- Flask apps only: Change the project name to match your app -->
112112
<add key="WSGI_HANDLER" value="FlaskAzurePublishExample.app"/>
113113
```
114114

115-
- **Django**: Two changes are needed to the `web.config` file for Django projects.
116-
117-
- Change the `WSGI_HANDLER` value to `django.core.wsgi.get_wsgi_application()`. The object is in the `wsgi.py` file.
115+
- **Django**: Two changes are needed to the *web.config* file for Django projects.
116+
117+
- Change the `WSGI_HANDLER` value to `django.core.wsgi.get_wsgi_application()`. The object is in the *wsgi.py* file.
118118

119119
```xml
120120
<!-- Django apps only -->
@@ -127,7 +127,7 @@ Next, modify your application's `web.config` file to include the full paths to t
127127
<add key="DJANGO_SETTINGS_MODULE" value="django_iis_example.settings" />
128128
```
129129

130-
1. **Django apps only**: In the Django project's `settings.py` file, add your site URL domain or IP address to the `ALLOWED_HOSTS` entry. Replace '1.2.3.4' with your URL or IP address:
130+
1. **Django apps only**: In the Django project's *settings.py* file, add your site URL domain or IP address to the `ALLOWED_HOSTS` entry. Replace '1.2.3.4' with your URL or IP address:
131131

132132
```python
133133
# Change the URL or IP address to your specific site
@@ -137,17 +137,17 @@ Next, modify your application's `web.config` file to include the full paths to t
137137
If you don't add your URL to the array results, you see the following error:
138138

139139
```output
140-
DisallowedHost at / Invalid HTTP_HOST header: '\<site URL\>'. You might need to add '\<site URL\>' to ALLOWED_HOSTS.
140+
DisallowedHost at / Invalid HTTP_HOST header: '<site URL>'. You might need to add '<site URL>' to ALLOWED_HOSTS.
141141
```
142142

143-
When the array is empty, Django automatically allows `'localhost'` and `'127.0.0.1'` as hosts. If you add your production URL, these host sites aren't automatically allowed. For this reason, you might want to maintain separate development and production copies of the `settings.py` file, or use environment variables to control the runtime values.
143+
When the array is empty, Django automatically allows `'localhost'` and `'127.0.0.1'` as hosts. If you add your production URL, these host sites aren't automatically allowed. For this reason, you might want to maintain separate development and production copies of the *settings.py* file, or use environment variables to control the runtime values.
144144

145145
## Deploy to IIS or a Windows virtual machine
146146

147-
When you have the correct `web.config` file in your project, you can publish to the computer that's running IIS from **Solution Explorer**. Right-click the project, select **Publish**, and then select **IIS, FTP, etc.**. In this situation, Visual Studio copies only the project files to the server. You're responsible for all server-side configuration.
147+
When you have the correct *web.config* file in your project, you can publish to the computer that's running IIS from **Solution Explorer**. Right-click the project, select **Publish**, and then select **IIS, FTP, etc.**. In this situation, Visual Studio copies only the project files to the server. You're responsible for all server-side configuration.
148148

149149
## Related content
150150

151-
- [IIS Configuration Reference](https://www.iis.net/configreference) (iis.net)
151+
- [IIS Configuration Reference on iis.net](https://www.iis.net/configreference)
152152
- [Install Python interpreters](installing-python-interpreters.md)
153-
- [Windows virtual machines on Azure](/azure/architecture/reference-architectures/n-tier/windows-vm)
153+
- [Run a Windows virtual machine on Azure](/azure/architecture/reference-architectures/n-tier/windows-vm)

0 commit comments

Comments
 (0)