- GeoDjango with PostGIS quick start guide

    How to create a new Django project?

    To start a project with Django, it is necessary to start the Bitnami Console. If you are using a Virtual Appliance or Cloud Image, you can run the commands below directly.

    You can find the projects folder located at:

    linux_platform.png On Linux:


    win_platform.png On Windows:

    For 2000, XP and 2003 Server:

    C:\Documents and Settings\user\Bitnami DjangoStack Projects

    For Vista, 7 and 2008 Server:

    C:\Users\user\Bitnami DjangoStack Projects

    mac_platform.png On OS X:


    From a console go to your projects folder and run the following command to create a new project:                             

    django-admin.py startproject my_new_project

    If you wish to create a new applicaction inside the created project execute the following commands as well:

    cd my_new_project
    python manage.py startapp my_new_app


    You can check your Django version executing the following command:

    python -c "import django; print(django.get_version())"

    For getting started with Django, check the official Django documentation for the version that you are using.


    How to start a Django project?  

    Before start to follow the steps, keep in mind that installdir is the installation directory that you configured during the installation process. If you are using a Virtual Appliance, a Cloud Image or Bitnami Cloud Hosting, the installation directory is: /opt/bitnami.

    For development tasks you can use the standalone server in Django executing the following command inside your project folder:

    python manage.py runserver ip:port

    ip and port are optional parameters. will be used by default if you don't specify any of them.

    Note that is only accessible from the local machine. If you are remotely accessing the server you should use the ip (or the server IP). Also make sure that the port is open in your firewall rules, for Bitnami Cloud hosting servers check how to access your machine documentation.


    For a production environment we recomend to configure Apache with mod_wsgi module before start serving your application. If you are using Bitnami Stacks and Virtual Appliances for Django, mod_wsgi is already installed and activated by default. 

    Django application configuration

    First, modify the WSGI application script file named 'wsgi.py' in the 'installdir/apps/django/django_projects/my_new_project/my_new_project' folder.

    Although the exact content may be different depending on your Django version. Ensure that the content is similar to the code below and you add your project to the path with sys.path.append.

    import os
    import sys
    os.environ.setdefault("PYTHON_EGG_CACHE", "installdir/apps/django/django_projects/my_new_project/egg_cache")
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "my_new_project.settings")
    from django.core.wsgi import get_wsgi_application
    application = get_wsgi_application()
    Apache configuration
    Create the conf folder in 'installdir/apps/django/django_projects/my_new_project/'. 
    mkdir installdir/apps/django/django_projects/my_new_project/conf

    Then, create these two files:

    touch installdir/apps/django/django_projects/my_new_project/conf/httpd-prefix.conf
    touch installdir/apps/django/django_projects/my_new_project/conf/httpd-app.conf
    On Unix you can run your application with mod_wsgi in daemon mode. Add the following code in httpd-app.conf :
      WSGIDaemonProcess wsgi-djangostack processes=2 threads=15 display-name=%{GROUP}
    WSGIScriptAlias /my_new_project 'installdir/apps/django/django_projects/my_new_project/my_new_project/wsgi.py'
    <Directory "installdir/apps/django/django_projects/my_new_project/my_new_project/">
        WSGIProcessGroup wsgi-djangostack
        WSGIApplicationGroup %{GLOBAL}
        <IfVersion < 2.3 >
            Order allow,deny
            Allow from all
        <IfVersion >= 2.3>
            Require all granted
    On Windows the daemon mode for mod_wsgi is not support and the configuration will be slightly different:
    WSGIScriptAlias /my_new_project 'installdir/apps/django/django_projects/my_new_project/my_new_project/wsgi.py'
    <Directory "installdir/apps/django/django_projects/my_new_project/my_new_project/">
        WSGIApplicationGroup %{GLOBAL}
        <IfVersion < 2.3 >
            Order allow,deny
            Allow from all
        <IfVersion >= 2.3>
            Require all granted

    In 'installdir/apps/django/django_projects/my_new_project/conf/httpd-prefix.conf' add this code:

    Include "installdir/apps/django/django_projects/my_new_project/conf/httpd-app.conf"

    Finally, add the line below in 'installdir/apache2/conf/bitnami/bitnami-apps-prefix.conf':

    Include "installdir/apps/django/django_projects/my_new_project/conf/httpd-prefix.conf"

    Then restart the Apache server and visit your project at http://localhost:8080/my_new_project

    Database configuration

    If you want to configure a database for your project, you can configure the "settings.py" file with the following settings. The examples below show how to configure the database connection with a database called "djangostack":

    • MySQL
     DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.mysql',
            'NAME': 'djangostack',
            'HOST': '/opt/bitnami/mysql/tmp/mysql.sock',                                                 
            'PORT': '3306',
            'USER': 'your_user',
            'PASSWORD': 'your_password'
    • PostgreSQL
        'default': {
            'ENGINE': 'django.db.backends.postgresql_psycopg2',
            'NAME': 'djangostack',
            'HOST': '/opt/bitnami/postgresql',
            'PORT': '5432',
            'USER': 'your_user',
            'PASSWORD': 'your_password'
    • SQLite
     DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.sqlite3',
            'NAME': '/opt/bitnami/apps/django/django_projects/Project/Project/Project.db',

    The database connection is configured to use a socket. If you are using DjangoStack on Windows, you should use 'HOST': '' .

    How to configure Django with Aptana or Eclipse?

    BitNami Stacks are self-contained and independent of your system. If you want to configure the Aptana development tool, you can load the Stack environment before using it.

    $ source installdir/scripts/setenv.sh
    $ /opt/Aptana_Studio_3/AptanaStudio3

    You can also integrate with Eclipse:

    $ source installdir/scripts/setenv.sh
    $ eclipse

    You can find a quick guide (spanish) at http://pategon.blogspot.com.es/2012/09/bitnami-djangostack-eclipse-pydev-aptana.html

    How to upgrade Django python package?

    Before upgrading Django make sure that your Django applications are compatible with the new version.

    Open the BitNami Console to load the BitNami environment if you are using the Native Installer. If you are using the Virtual Machine or the Cloud Image is not necessay.

    On Windows execute:

    pip install --upgrade Django --install-option="--prefix=\installdir\apps\django --install-lib=\installdir\apps\django --install-scripts=\installdir\apps\django\django\bin --install-data=\installdir\apps\django"

    On virtual machines and cloud images execute from the uncompressed directory:

    sudo pip install --upgrade Django --install-option="--prefix=/opt/bitnami/apps/django"

    On Linux and Mac OS X execute from the uncompressed directory:

    pip install --upgrade Django --install-option="--prefix=/opt/bitnami/apps/django"

    If you want a specific version of Django (not the latest one) you can specify Django==<version> instead (example: Django==1.6.5)

    Edit the django-admin.py script (that you can find in apps/django/bin) and change the first line to use python instead of .python2.7.bin:



    Tag page (Edit tags)
    • No tags
    Pages that link here
    Page statistics
    74518 view(s), 39 edit(s) and 11725 character(s)


    You must login to post a comment.

    Attach file