Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

467
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!