Skip to content

Commit e82673a

Browse files
authored
[Functions] Better fix for the Python CLI quickstart
1 parent abe3b5a commit e82673a

File tree

1 file changed

+5
-27
lines changed

1 file changed

+5
-27
lines changed

Diff for: articles/azure-functions/create-first-function-cli-python.md

+5-27
Original file line numberDiff line numberDiff line change
@@ -141,35 +141,13 @@ In this section, you create a function project and add an HTTP triggered functio
141141

142142
The environment now contains various files for the project, including configuration files named [*local.settings.json*](functions-develop-local.md#local-settings-file) and [*host.json*](functions-host-json.md). Because *local.settings.json* can contain secrets downloaded from Azure, the file is excluded from source control by default in the *.gitignore* file.
143143

144-
1. The file `function_app.py` can include all functions within your project. Open this file and replace the existing contents with the following code that defines an HTTP triggered function endpoint named `HttpExample`:
144+
1. Add a function to your project by using the following command, where the `--name` argument is the unique name of your function (HttpExample) and the `--template` argument specifies the function's trigger (HTTP).
145145

146-
```python
147-
import azure.functions as func
148-
import logging
149-
150-
app = func.FunctionApp()
151-
152-
@app.route(route="HttpExample", auth_level=func.AuthLevel.ANONYMOUS)
153-
def test_function(req: func.HttpRequest) -> func.HttpResponse:
154-
logging.info('Python HTTP trigger function processed a request.')
155-
156-
name = req.params.get('name')
157-
if not name:
158-
try:
159-
req_body = req.get_json()
160-
except ValueError:
161-
pass
162-
else:
163-
name = req_body.get('name')
164-
165-
if name:
166-
return func.HttpResponse(f"Hello, {name}. This HTTP triggered function executed successfully.")
167-
else:
168-
return func.HttpResponse(
169-
"This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response.",
170-
status_code=200
171-
)
146+
```console
147+
func new --name HttpExample --template "HTTP trigger" --authlevel "anonymous"
172148
```
149+
150+
If prompted, choose the **ANONYMOUS** option. `func new` adds an HTTP trigger endpoint named `HttpExample` to the `function_app.py` file, which is accessible without authentication.
173151
174152
1. Open the local.settings.json project file and verify that the `AzureWebJobsFeatureFlags` setting has a value of `EnableWorkerIndexing`. This is required for Functions to interpret your project correctly as the Python v2 model. You'll add this same setting to your application settings after you publish your project to Azure.
175153

0 commit comments

Comments
 (0)