Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

477
Visualizações
Link Azure Connection String with Django WebApp?

It's my first website on Azure with Python. I developed before with .NET. Sorry if my question is a basic one.

I deployed my Django website on Azure. It works fine with the DB settings in the settings.py.

Next step, I thought, is to transfer the DB settings to Azure's Application Settings - Connection Strings, what I did.

I am aware that I need the prefix MYSQLCONNSTR_connectionString1.

How can I now link my Django/Python WebApp with the Connection String in the Azure Application Settings?

I would be very grateful for help.

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

Just use import os to import os package in your Django code like settings.py, then get these environment variables which be defined in App settings or Connection strings of the tab Application settings on Azure portal via the code os.getenv("<environ-var-name>").

For the environment variable defined in App settings, you just pass the variable name defined like VARNAME as the argument for os.getenv().

To get the value of the environment variable defined in Connection strings, you need to add the different prefix or surfix for the variable name like VARNAME, as below.

  1. For SQL Database, using prefix SQLAZURECONNSTR with infix symbol _ for VARNAME is SQLAZURECONNSTR_VARNAME.

  2. For SQL Server, using prefix SQLCONNSTR with infix symbol _ for VARNAME is SQLCONNSTR_VARNAME.

  3. For MySQL, using prefix MYSQLCONNSTR with infix symbol _ for VARNAME is MYSQLCONNSTR_VARNAME.

  4. For Custom, using surfix MYSQLCONNSTR with infix symbol _ for VARNAME is VARNAME_CONNECTSTRING.

Hope it helps.

over 4 years ago · Santiago Trujillo Relatório

0

I couldn't connect the database via Environment Variables in Azure's Application settings - Connection Strings, though I tried various approaches. Still would be grateful for help how it can be done.

What worked instead, reading https://godjango.com/blog/working-with-environment-variables-in-python/:

Enter in Azure Application settings - App settings the single DB connection values:

KEY                  VALUE
DATABASE_NAME:       <database>
DATABASE_USER:       <dbuser>
DATABASE_PASSWORD:   <dbpassword>
DATABASE_HOST:       <host>
DATABASE_PORT:       <port>

And in settings.py

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': os.environ.get('DATABASE_NAME', ''),
        'USER': os.environ.get('DATABASE_USER', ''),
        'PASSWORD': os.environ.get('DATABASE_PASSWORD', ''),
        'HOST': os.environ.get('DATABASE_HOST', ''),
        'PORT': os.environ.get('DATABASE_PORT', ''),    
    }
}
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda