title: Making a multi-tenant application on flask
body: <p>I am trying to make a multi-tenant application using Flask, I have been following this guide, I am using Postgres sql for the database:</p>
  
  <p><a href="https://medium.com/@smirnov.am/multitenancy-with-flask-6f5375a34f55" rel="nofollow noreferrer">https://medium.com/@smirnov.am/multitenancy-with-flask-6f5375a34f55</a></p>
  
  <p>So my point of confusion is that when I try to redirect to the specified url for I keep getting a internal server error, when I look at the logs this is what I get: </p>
  
  <p><code>TypeError: index() got an unexpected keyword argument 'organization_name'</code></p>
  
  <p>While following the guide I am going the same exact steps as he is doing, I am just not able to get the final output to show that it does work.</p>
  
  <p>This is how I am structuring my app.route</p>
  
  <pre class="lang-py prettyprint-override"><code>@app.route("/&lt;organization_name&gt;/users")
  def index(organization__name):
      organization_session = get_organization_session(organization__name)
      if not organization_session:
          print(404)
      users = organization_session.query(Organization).all()
      return jsonify({organization__name: [i.username for i in users]})
  </code></pre>
  
  <p>And this is how I am setting my multi-tenant set up:</p>
  
  <pre class="lang-py prettyprint-override"><code>
  DB_URI = my postgres uri 
  
  # Manages the the multiple dbs for the organization
  
  @simple_cache
  def get_known_organizations():
      organizations = Organization.query.all()
      return [o.name for o in organizations]
  
  
  def prepare_bind(organization):
      if organization not in current_app.config['SQLALCHEMY_BINDS']:
          current_app.config['SQLALCHEMY_BINDS'][organization] = DB_URI.format(organization)
      return current_app.config['SQLALCHEMY_BINDS'][organization]
  
  
  def get_organization_session(organization):
      if organization not in get_known_organizations():
          return None
      prepare_bind(organization)
      engine = db.get_engine(current_app, bind=organization)
      session_maker = db.sessionmaker()
      session_maker.configure(bind=engine)
      sesh = session_maker()
      return sesh
  </code></pre>
  
  <p>Any help would be great appreciated </p>