from flask import Blueprint, render_template
from flask_login import login_required

challenges = Blueprint('challenges', __name__)


@challenges.route('/challenges', methods=['GET'])
@login_required
def challenges_view():
    return render_template('challenges.html', page="Challenges")

import requests

from flask import Blueprint, render_template, jsonify
from flask_login import login_required

challenges = Blueprint('challenges', __name__)


@challenges.route('/challenges', methods=['GET'])
@login_required
def challenges_view():
    return render_template('challenges.html', page="Challenges")


@challenges.route('/exercises', methods=['GET'])
@login_required
def api_exercises():
    exercises = requests.get("http://localhost:8000/").json()
    result = {
        "exercises":
            []
    }
    for current in exercises['exercises']:
        result['exercises'].append({
            "name": current.get('name', 'unknown'),
            "category": current.get('answers')[0].split(".")[1],
            "solved": 0,
            "cost": 100
        })
    return jsonify(result)

Implement demo 'exercises' api method.
Implement demo 'exercises' api method.

+ import requests
+ 
- from flask import Blueprint, render_template
+ from flask import Blueprint, render_template, jsonify
  from flask_login import login_required
  
  challenges = Blueprint('challenges', __name__)
  
  
  @challenges.route('/challenges', methods=['GET'])
  @login_required
  def challenges_view():
      return render_template('challenges.html', page="Challenges")
  
+ 
+ @challenges.route('/exercises', methods=['GET'])
+ @login_required
+ def api_exercises():
+     exercises = requests.get("http://localhost:8000/").json()
+     result = {
+         "exercises":
+             []
+     }
+     for current in exercises['exercises']:
+         result['exercises'].append({
+             "name": current.get('name', 'unknown'),
+             "category": current.get('answers')[0].split(".")[1],
+             "solved": 0,
+             "cost": 100
+         })
+     return jsonify(result)
+ 
Implement demo 'exercises' api method.
## Code Before:
from flask import Blueprint, render_template
from flask_login import login_required

challenges = Blueprint('challenges', __name__)


@challenges.route('/challenges', methods=['GET'])
@login_required
def challenges_view():
    return render_template('challenges.html', page="Challenges")

## Instruction:
Implement demo 'exercises' api method.
## Code After:
import requests

from flask import Blueprint, render_template, jsonify
from flask_login import login_required

challenges = Blueprint('challenges', __name__)


@challenges.route('/challenges', methods=['GET'])
@login_required
def challenges_view():
    return render_template('challenges.html', page="Challenges")


@challenges.route('/exercises', methods=['GET'])
@login_required
def api_exercises():
    exercises = requests.get("http://localhost:8000/").json()
    result = {
        "exercises":
            []
    }
    for current in exercises['exercises']:
        result['exercises'].append({
            "name": current.get('name', 'unknown'),
            "category": current.get('answers')[0].split(".")[1],
            "solved": 0,
            "cost": 100
        })
    return jsonify(result)
