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 Flask REST API Resourceful Blueprints Blueprints

ValueError: 'name' may not contain a dot '.' character.

I don't understand what this means

raise ValueError("'name' may not contain a dot '.' character.") ValueError: 'name' may not contain a dot '.' character.

Some of my codes which I think might have caused the error are below:

api.add_resource(
    CourseList,
    '/api/v1/courses',   # URI
    endpoint = 'courses'   # what we are going to call this end point
)

2 Answers

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 67,622 Points

Hey jun cheng wong, according to the flask class Blueprint src code, line 194, checks if the Blueprint is initialized with a name that contains a dot (’.’). More of your code is needed to see why name is set with a dot.

Post back if you need more help. Good luck!!!

Yeah, I think the main problem is that there is a dot inside 'resources.courses'. In my case, the 'courses' file is under the folder named "resources". I don't know how to fix it, appreciate if you can help

courses_api = Blueprint('resources.courses', __name__)   # first parameter is the file path
api = Api(courses_api)

api.add_resource(
    CourseList,
    '/api/v1/courses',   # endpoint
    endpoint = 'courses'   # what we are going to call this end point
)

api.add_resource(
    Course,
    '/api/v1/courses/<int:id>',   # endpoint URI
    endpoint = 'course'   # what we are going to call this end point
)
Iris Avalon
Iris Avalon
14,477 Points

Adding this comment in case anyone else is having this issue:

The line causing problem in the above snippet is:

courses_api = Blueprint('resources.courses', __name__)

The first argument in the Blueprint constructor cannot have a dot character in it. Looking at the flask documentation for the Blueprint class, the first positional argument in the constructor is prepended to the endpoint name, that's all:

name (str) – The name of the blueprint. Will be prepended to each endpoint name.

So you can change 'resources.courses' to something like just 'course' and the app should build just fine