Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python

get an AssertionError: View function mapping is overwriting an existing endpoint function: resources.courses

from flask import jsonify, Blueprint

from flask_restful import Resource, Api

import models

class CourseList(Resource):
    def get(self):
        return jsonify({"courses" : [{"title": "Python Basics"}]})


class Course(Resource):
    def get(self, id):
        return jsonify({"title": "Python Basics"})

    def put(self, id):
        return jsonify({"title": "Python Basics"})

    def delete(self, id):
        return jsonify({"title": "Python Basics"})

courses_api = Blueprint('resources.courses', __name__,)
api = Api(courses_api)
api.add_resource(
    CourseList,
    '/api/v1/courses',
    endpoint = 'courses'
)
api.add_resource(
    Course,
    '/api/v1/courses/<int:id>',
    endpoint = 'courses'
)
from flask import Flask

import models 
from resources.courses import courses_api

DEBUG = True
HOST = "localhost"
PORT = 8000

app = Flask(__name__)
app.register_blueprint(courses_api)

@app.route('/')
def index():
    return "Hello World"


if __name__ == '__main__':
    models.initialize()
    app.run(debug=DEBUG, host=HOST, port=PORT)

[MOD: added ```python formatting -cf]

1 Answer

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,441 Points

Looks like the endpoints have the same name:

endpoint = 'courses'