Join us on March 29th for Developer Days!Learn More

Connect a Django application to Neon

Set up a Neon project in seconds and connect from a Django application

To connect to Neon from a Django application:

  1. Create a Neon project
  2. Configure Django connection settings

Create a Neon project

If you do not have one already, create a Neon project. Save your connection details including your password. They are required when defining connection settings.

To create a Neon project:

  1. Navigate to the Projects page in the Neon Console.
  2. Click New Project.
  3. Specify a name, a PostgreSQL version, a region, and click Create Project.

For additional information about creating projects, see Set up a project.

Configure Django connection settings

Connecting to Neon requires configuring database connection settings in your Django project's file.

In your Django project, navigate to the DATABASES section of your file and modify the connection details as shown:

    'default': {
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': '<dbname>',
        'USER': '<user>',
        'PASSWORD': '<password>',
        'HOST': '<hostname>',
        'PORT': '<port>',


  • <dbname> is the name of the database. The default Neon database is neondb.
  • <user> is the database user.
  • <password> is the database user's password, which is provided to you when you create a project.
  • <hostname> is the hostname of the branch's compute endpoint. The hostname has an ep- prefix and appears similar to this:
  • <port> is the PostgreSQL port number. Neon uses the default port, 5432.


Neon places computes into an idle state and closes connections after 5 minutes of inactivity (see Compute lifecycle). To avoid connection errors, you can set the Django CONN_MAX_AGE setting to 0 to close database connections at the end of each request so that your application does not attempt to reuse connections that were closed by Neon. From Django 4.1, you can use a higher CONN_MAX_AGE setting in combination with the CONN_HEALTH_CHECKS setting to enable connection reuse while preventing errors that might occur due to closed connections. For more information about these configuration options, see Connection management, in the Django documentation.

You can find all of the connection details listed above, except for your password, in the Connection Details widget on the Neon Dashboard. For more information, see Connect from any application. If you have misplaced your password, see Reset a password.

For additional information about Django project settings, see Django Settings: Databases, in the Django documentation.


Running Django tests is currently not supported. The Django test runner must be able to create a database for tests, which is not yet supported by Neon.

Need help?

Send a request to, or join the Neon community forum.

Edit this page
Was this page helpful?