Hat
Hat

Reputation: 1731

How to set up Django Azure website to access database

I am trying to set up my Django site using Azure Websites (not an Azure VM). I got a site with some static pages up and running, and I created an Azure SQL Database, but how do I connect the Django site to use the Azure db?

Upvotes: 2

Views: 626

Answers (2)

Satch421
Satch421

Reputation: 1

I understand you can use something like the following in your settings.py file

DATABASES = {
  'default': {
    'ENGINE': 'django.db.backends.postgresql',
    'NAME': os.environ['DBNAME'],
    'HOST': hostname + ".postgres.database.azure.com",
    'USER': os.environ['DBUSER'] + "@" + hostname,
    'PASSWORD': os.environ['DBPASS'] 
  }
}

Upvotes: 0

ndpu
ndpu

Reputation: 22561

Try django-pyodbc-azure

django-pyodbc-azure is a refined fork of django-pyodbc, a Django MS SQL Server external DB backend that uses ODBC by employing the pyodbc library. It supports MS SQL Server and Windows Azure SQL Database.

Features

  • Supports Django 1.9.6
  • Supports Microsoft SQL Server 2005, 2008/2008R2, 2012, 2014, 2016 and Azure SQL Database
  • Supports LIMIT+OFFSET and offset w/o LIMIT emulation.
  • Passes most of the tests of the Django test suite.
  • Compatible with SQL Server , SQL Server Native Client , Micosoft ODBC Driver 11 for SQL Server on Windows and FreeTDS ODBC drivers.

Upvotes: 3

Related Questions