Skip to content

Commit ee72389

Browse files
committed
Update heart usage
1 parent c3f7b35 commit ee72389

File tree

2 files changed

+32
-27
lines changed

2 files changed

+32
-27
lines changed

articles/azure-app-configuration/howto-telemetry-python.md

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ ms.service: azure-app-configuration
66
author: mrm9084
77
ms.author: mametcal
88
ms.topic: how-to
9-
ms.date: 03/05/2025
9+
ms.date: 05/06/2025
1010
---
1111

1212
# Tutorial: Enable telemetry for feature flags in a Python application (preview)
@@ -50,19 +50,38 @@ In this tutorial, you use telemetry in your Python application to track feature
5050
```python
5151
from featuremanagement import track_event
5252
53-
@bp.route("/", methods=["GET", "POST"])
54-
def index():
55-
context = {}
56-
user = ""
53+
@bp.route("/heart", methods=["POST"])
54+
def heart():
5755
if current_user.is_authenticated:
5856
user = current_user.username
59-
context["user"] = user
60-
else:
61-
context["user"] = "Guest"
62-
if request.method == "POST":
63-
# Update the post request to track liked events
57+
58+
# Track the appropriate event based on the action
6459
track_event("Liked", user)
65-
return redirect(url_for("pages.index"))
60+
return jsonify({"status": "success"})
61+
```
62+
63+
1. Open `index.html` and update the code to implement the like button. The like button sends a POST request to the `/heart` endpoint when clicked.
64+
65+
```html
66+
<script>
67+
function heartClicked(button) {
68+
var icon = button.querySelector('i');
69+
70+
// Toggle the heart icon appearance
71+
icon.classList.toggle('far');
72+
icon.classList.toggle('fas');
73+
74+
// Only send a request to the dedicated heart endpoint when it's a like action
75+
if (icon.classList.contains('fas')) {
76+
fetch('/heart', {
77+
method: 'POST',
78+
headers: {
79+
'Content-Type': 'application/json',
80+
}
81+
});
82+
}
83+
}
84+
</script>
6685
```
6786
6887
## Build and run the app

articles/azure-app-configuration/howto-variant-feature-flags-python.md

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ ms.author: mametcal
88
ms.service: azure-app-configuration
99
ms.devlang: python
1010
ms.topic: how-to
11-
ms.date: 12/02/2024
11+
ms.date: 05/06/2025
1212
---
1313

1414
# Use variant feature flags in a Python application
@@ -118,7 +118,7 @@ If you already have a Python Flask web app, you can skip to the [Use the variant
118118
119119
bp = Blueprint("pages", __name__)
120120
121-
@bp.route("/", methods=["GET", "POST"])
121+
@bp.route("/", methods=["GET"])
122122
def index():
123123
context = {}
124124
user = ""
@@ -127,8 +127,6 @@ If you already have a Python Flask web app, you can skip to the [Use the variant
127127
context["user"] = user
128128
else:
129129
context["user"] = "Guest"
130-
if request.method == "POST":
131-
return redirect(url_for("pages.index"))
132130
133131
quotes = [
134132
Quote("You cannot change what you are, only what you do.", "Philip Pullman"),
@@ -277,11 +275,6 @@ If you already have a Python Flask web app, you can skip to the [Use the variant
277275
</div>
278276
<script>
279277
function heartClicked(button) {
280-
var icon = button.querySelector('i');
281-
icon.classList.toggle('far');
282-
icon.classList.toggle('fas');
283-
}
284-
</script>
285278
{% endblock %}
286279
```
287280
@@ -462,13 +455,6 @@ If you already have a Python Flask web app, you can skip to the [Use the variant
462455
from featuremanagement.azuremonitor import track_event
463456
from . import azure_app_config, feature_manager
464457
465-
...
466-
# Update the post request to track liked events
467-
if request.method == "POST":
468-
track_event("Liked", user)
469-
return redirect(url_for("pages.index"))
470-
471-
...
472458
# Update greeting_message to variant
473459
greeting = feature_manager.get_variant("Greeting", user)
474460
greeting_message = ""

0 commit comments

Comments
 (0)