Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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 66,111 Points

Looks like the endpoints have the same name:

endpoint = 'courses'