title: Flask Blueprint AttributeError: 'module' object has no attribute 'name' error
body: <p>My API is being built to allow developers to extend it's functionality. My plan is to do this by providing an "extensions" directory where they can drop in Blueprints and they will be dynamically loaded. This is the code I am utilizing to import (modifed from this <a href="https://lextoumbourou.com/blog/posts/dynamically-loading-modules-and-classes-in-python/">tutorial</a>)</p>
  
  <pre><code>from flask import Flask
  
  import pkgutil
  import sys
  
  app = Flask(__name__)
  
  EXTENSIONS_DIR = "extensions"
  modules = pkgutil.iter_modules(path=[EXTENSIONS_DIR])
  for loader, mod_name, ispkg in modules: 
      if mod_name not in sys.modules:
          # It imports fine
          loaded_mod = __import__(EXTENSIONS_DIR+"."+mod_name+"."+mod_name, fromlist=[mod_name])
          # It does not register
          app.register_blueprint(loaded_mod)
  </code></pre>
  
  <p>This is the directory layout of my project. The <code>extensions</code> directory is where developers drop in their expanded functionality.</p>
  
  <pre><code>/root
      /extensions
          /extension1
              __init__.py
              extension1.py
          /extension2
              __init__.py
              extension2.py
      simple_example.py
  </code></pre>
  
  <p>The problem is that I get this error and am not sure what it is telling me.</p>
  
  <pre><code>&gt;python simple_example.py
  Traceback (most recent call last):
    File "simple_example.py", line 14, in &lt;module&gt;
      app.register_blueprint(loaded_mod)
    File "C:\Python27\lib\site-packages\flask\app.py", line 62, in wrapper_func
      return f(self, *args, **kwargs)
    File "C:\Python27\lib\site-packages\flask\app.py", line 880, in register_blueprint
      if blueprint.name in self.blueprints:
  AttributeError: 'module' object has no attribute 'name'
  </code></pre>
  
  <p>A simple extension looks like this</p>
  
  <pre><code>from flask import Blueprint
  
  extension1 = Blueprint('extension1', __name__)
  
  @extension1.route("/my_route")
  def treasure_list():
      return "list of objects"
  </code></pre>
  
  <p>How do I solve the <code>AttributeError</code> in a way that allows my <code>app.register_blueprint</code> call to succeed?</p>