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 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 68,457 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

Rafael Gomes
Rafael Gomes
6,963 Points

thank you, changing 'resources.courses' to just 'courses' worked for me