I'm developing a Flask application and I would like to know if exist any other way to improve the method I implemented the subdomain.
Current method:
Structure:
arquivos/
|
├── gerenciador/
| └ cadastro/
| ├── templates/
| |
| ├── __init__.py
| └── cadastro.py
|
├── __init__.py
└── views.py
file __ init __.py (arquivos/)
from flask import *
from .gerenciador.cadastro.cadastro import cadastro
app = Flask(__name__)
app.register_blueprint(cadastro, url_prefix='/cadastro', subdomain='<subdomain>')
import arquivos.views
file views.py (arquivos/)
from flask import *
from . import app
@app.route("/", subdomain="<subdomain>")
def username_index(subdomain):
pass
file __ init __.py (gerenciador/cadastro/)
from flask import *
cadastro = Blueprint('cadastro', __name__, template_folder='templates')
from . import cadastro
file cadastro.py (gerenciador/cadastro/)
from flask import *
from . import cadastro
@cadastro.route('/teste', subdomain='<subdomain>')
def cadastro_inicio(subdomain):
return 'cadastro ' + str(subdomain) + ', hello!'
This method is working, but every time I need to create a new route in gerenciador/cadastro/cadastro.py I need to repeat the "subdomain='< subdomain >'" and pass the "subdomain" to the function. Is possible to make it dynamic (without use subdomain in this file)?
Obs: If subdomain is supressed I get this error:
typeError: name_of_the_function() got an unexpected keyword argument 'subdomain'