Crie e registre um Blueprint
Defina um Blueprint e associe-o ao aplicativo.
Crie e registre um Blueprint é uma aula grátis de Flask Academy no CoddyKit. Esta é a aula 2 de 4. Você pode ler a aula completa abaixo gratuitamente — depois pratica ao vivo no navegador com um editor de código integrado e um tutor de IA 24/7. Faz parte do caminho de aprendizado de Flask Academy, e seu progresso é sincronizado entre a web e o app CoddyKit. O curso de Flask Academy inclui 4 aulas no total.
Partes desta aula ainda não foram traduzidas e aparecem em inglês.
Two Steps to a Blueprint
Working with a blueprint is two moves: first you define it in its own module, then you register it on the app. Let us walk through both.
Import the Blueprint Class
Everything starts with one import. The Blueprint class comes straight from flask, just like the Flask app object does.
from flask import BlueprintCreate the Blueprint Object
You build a blueprint by giving it a name and import_name. The name uniquely identifies this blueprint inside your whole app.
blog = Blueprint("blog", __name__)What __name__ Does
That second argument, __name__, tells the blueprint where it lives so Flask can later find its templates and static files.
Routes on the Blueprint
Inside the module you attach views with @blog.route instead of @app.route. Same idea, but bound to the blueprint.
@blog.route("/posts")
def posts():
return "All posts"Still Dormant for Now
Defining routes is not enough. Until you register the blueprint, none of its URLs respond. The blueprint is inert on its own.
Import It in the App
Over in your app setup, you import the blueprint object from its module so the app can take ownership of it.
from blog.routes import blogRegister on the App
One call wires everything up. register_blueprint copies the blueprint routes onto the app and makes them live.
app.register_blueprint(blog)Order of Operations
Create the app, import the blueprint, then register it. Get this sequence right and your feature routes spring to life. ✅
Endpoint Names Get Namespaced
A view named posts inside the blog blueprint is referenced as blog.posts. The blueprint name becomes a tidy prefix for endpoints.
Avoiding Circular Imports
Keep the blueprint in its own file and import it where you build the app. This structure sidesteps painful circular import errors.
Quick Check
Which call actually makes a blueprint active?
Recap
Define a Blueprint with a name and __name__, add routes with @bp.route, then call register_blueprint on the app to make them live. 🎉
Perguntas Frequentes
A aula “Crie e registre um Blueprint” é grátis?
Sim — o texto completo de “Crie e registre um Blueprint” é grátis para ler aqui na web. Para praticá-la interativamente (um editor de código integrado e um tutor de IA 24/7) e desbloquear o restante do curso de Flask Academy, atualize para CoddyKit PRO. O curso de Flask Academy inclui 4 aulas no total.
O que vou aprender em “Crie e registre um Blueprint”?
Defina um Blueprint e associe-o ao aplicativo. Você pratica Flask Academy com código prático que executa diretamente no navegador, e um tutor de IA 24/7 responde suas dúvidas enquanto trabalha na aula.
Preciso ter experiência prévia para começar Flask Academy?
Nenhuma experiência prévia é necessária. Flask Academy no CoddyKit é estruturado para alunos iniciantes até avançados, então você pode começar aqui ou desde o início e aprender no seu ritmo. Esta é a aula 2 de 4.
Quanto tempo leva a aula “Crie e registre um Blueprint”?
A maioria das aulas CoddyKit leva cerca de 5–10 minutos. Cada uma é compacta e interativa, então você faz progresso constante e retoma exatamente de onde parou entre web e app.
Posso escrever e executar código nesta aula de Flask Academy?
Sim. Cada aula de Flask Academy inclui um editor de código integrado, então você escreve e executa código real direto no navegador e recebe feedback de IA instantaneamente — nenhuma configuração local necessária.
Todas as aulas deste curso
- Por que os Blueprints vencem um único arquivo gigante
- Crie e registre um Blueprint
- Prefixos de URL e url_for em Blueprints
- Modelos e arquivos estáticos específicos do Blueprint