Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

472
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda