Skip to content

Commit ec32bc5

Browse files
authored
correct python code for db-connected function app
1 parent 211d345 commit ec32bc5

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

articles/azure-functions/functions-add-output-binding-azure-sql-vs-code.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -223,16 +223,16 @@ Update *HttpExample\\function_app.py* to match the following code. Add the `toDo
223223
import azure.functions as func
224224
import logging
225225
from azure.functions.decorators.core import DataType
226+
import uuid
226227

227228
app = func.FunctionApp()
228229

229230
@app.function_name(name="HttpTrigger1")
230-
@app.route(route="hello", auth_level=func.AuthLevel.ANONYMOUS)
231-
@app.generic_output_binding(arg_name="toDoItems", type="sql", CommandText="dbo.ToDo", ConnectionStringSetting="SqlConnectionString"
232-
data_type=DataType.STRING)
231+
@app.route(route="hello", auth_level="anonymous")
232+
@app.generic_output_binding(arg_name="toDoItems", type="sql", CommandText="dbo.ToDo", ConnectionStringSetting="SqlConnectionString",data_type=DataType.STRING)
233233
def test_function(req: func.HttpRequest, toDoItems: func.Out[func.SqlRow]) -> func.HttpResponse:
234234
logging.info('Python HTTP trigger function processed a request.')
235-
name = req.params.get('name')
235+
name = req.get_json().get('name')
236236
if not name:
237237
try:
238238
req_body = req.get_json()
@@ -242,7 +242,7 @@ def test_function(req: func.HttpRequest, toDoItems: func.Out[func.SqlRow]) -> fu
242242
name = req_body.get('name')
243243

244244
if name:
245-
toDoItems.set(func.SqlRow({"id": uuid.uuid4(), "title": name, "completed": false, url: ""}))
245+
toDoItems.set(func.SqlRow({"Id": str(uuid.uuid4()), "title": name, "completed": False, "url": ""}))
246246
return func.HttpResponse(f"Hello {name}!")
247247
else:
248248
return func.HttpResponse(

0 commit comments

Comments
 (0)