2

I'm new to Flask blueprints, and I was wondering what the best practice is for implementing reusable blueprints such as flask-social-blueprint or flask-users-blueprint? Should I:

  • copy-paste the code into my project and overwrite whatever I want to change, or
  • import from the blueprint and then write overriding functions in a separate module?

In other words, are blueprints meant to be boilerplate files that save you from typing, or are they like Flask "extensions" and other Python modules to be imported without changing the original code?

Hippo
  • 450
  • 8
  • 22
  • Related: [What are Flask Blueprints exactly?](http://stackoverflow.com/q/24420857/135978) – Sean Vieira Jan 08 '16 at 06:01
  • @SeanVieira I saw the analogy. I think my question here would be: am I supposed to use the standard, readymade mold and chisel the results, or reshape the mold itself before using it in my own project? – Hippo Jan 08 '16 at 07:14
  • It depends on the project, but if it's an actual library and not just an example, then you should add it as a dependency, import the blueprints, etc. and register it with your app, overriding behavior as you need to - it's an extension, not a code snippet ;-) – Sean Vieira Jan 08 '16 at 07:17
  • @SeanVieira Thanks, I think that more or less answers my question. Maybe add it as an answer so I can mark it? :-) – Hippo Jan 14 '16 at 11:00

1 Answers1

1

It depends on the project, but if it's an actual library and not just an example, then you should add it as a dependency, import the blueprints, etc. and register it with your app, overriding behavior as you need to. Blueprints are extensions of your application, not a downloadable code snippet like (for example) the HTML5 Boilerplate.

Quoting from the documentation:

A blueprint in Flask is ... a set of operations which can be registered on an application, even multiple times. The basic concept of blueprints is that they record operations to execute when registered on an application.

Sean Vieira
  • 155,703
  • 32
  • 311
  • 293