Index: django/conf/project_template/settings/main.py
===================================================================
--- django/conf/project_template/settings/main.py	(revision 851)
+++ django/conf/project_template/settings/main.py	(working copy)
@@ -15,6 +15,7 @@
 DATABASE_USER = ''             # Not used with sqlite3.
 DATABASE_PASSWORD = ''         # Not used with sqlite3.
 DATABASE_HOST = ''             # Set to empty string for localhost. Not used with sqlite3.
+DATABASE_PORT = ''             # Set to empty string for default. Not used with sqlite3.
 
 SITE_ID = 1
 
Index: django/conf/global_settings.py
===================================================================
--- django/conf/global_settings.py	(revision 851)
+++ django/conf/global_settings.py	(working copy)
@@ -50,6 +50,7 @@
 DATABASE_USER = ''
 DATABASE_PASSWORD = ''
 DATABASE_HOST = ''             # Set to empty string for localhost
+DATABASE_PORT = ''             # Set to empty string for default
 
 # Host for sending e-mail.
 EMAIL_HOST = 'localhost'
Index: django/core/db/backends/postgresql.py
===================================================================
--- django/core/db/backends/postgresql.py	(revision 851)
+++ django/core/db/backends/postgresql.py	(working copy)
@@ -15,7 +15,7 @@
         self.queries = []
 
     def cursor(self):
-        from django.conf.settings import DATABASE_USER, DATABASE_NAME, DATABASE_HOST, DATABASE_PASSWORD, DEBUG, TIME_ZONE
+        from django.conf.settings import DATABASE_USER, DATABASE_NAME, DATABASE_HOST, DATABASE_PORT, DATABASE_PASSWORD, DEBUG, TIME_ZONE
         if self.connection is None:
             if DATABASE_NAME == '':
                 from django.core.exceptions import ImproperlyConfigured
@@ -27,6 +27,8 @@
                 conn_string += " password=%s" % DATABASE_PASSWORD
             if DATABASE_HOST:
                 conn_string += " host=%s" % DATABASE_HOST
+	    if DATABASE_PORT:
+		conn_string += " port=%s" % DATABASE_PORT
             self.connection = Database.connect(conn_string)
             self.connection.set_isolation_level(1) # make transactions transparent to all cursors
         cursor = self.connection.cursor()
Index: django/core/db/backends/mysql.py
===================================================================
--- django/core/db/backends/mysql.py	(revision 851)
+++ django/core/db/backends/mysql.py	(working copy)
@@ -53,10 +53,10 @@
         self.queries = []
 
     def cursor(self):
-        from django.conf.settings import DATABASE_USER, DATABASE_NAME, DATABASE_HOST, DATABASE_PASSWORD, DEBUG
+        from django.conf.settings import DATABASE_USER, DATABASE_NAME, DATABASE_HOST, DATABASE_PORT, DATABASE_PASSWORD, DEBUG
         if self.connection is None:
             self.connection = Database.connect(user=DATABASE_USER, db=DATABASE_NAME,
-                passwd=DATABASE_PASSWORD, host=DATABASE_HOST, conv=django_conversions)
+                passwd=DATABASE_PASSWORD, host=DATABASE_HOST, port=DATABASE_PORT, conv=django_conversions)
         if DEBUG:
             return base.CursorDebugWrapper(MysqlDebugWrapper(self.connection.cursor()), self)
         return self.connection.cursor()
