- 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 AMI, you can run the commands below directly.

    You should create your new project inside Django projects folder located at:

    linux_platform.png On Linux:

    installdir/apps/django/django_projects
    

    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:

    /Applications/djangostack-version/apps/django/django_projects
    

    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
    

    How to start a Django project?  

    There are two ways to start a Django project depending of if it is a development or a production environment.

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

    $ python manage.py runserver ip:port
    

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

    Note that 127.0.0.1 is only accessible from the local machine. If you are remotely accessing the server you should use the ip 0.0.0.0 (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.

    The other way is strongly recommended for production environments. It requires to configure Apache with mod_wsgi module before start serving your application. BitNami Stacks and Virtual Appliances for Django include mod_wsgi installed and activated by default. So you just need to create WSGI application script file and configure Apache to load it.

    First, create the WSGI application script file named 'projectName.wsgi' in 'installdir/apps/django/scripts' folder. Add the following content setting the correct the paths and project name:

    import os, sys
    sys.path.append('/path/to/your/django/projects/folder')
    sys.path.append('/path/to/your/project/folder')
    os.environ['DJANGO_SETTINGS_MODULE'] = 'projectName.settings'
    
    import django.core.handlers.wsgi
    
    application = django.core.handlers.wsgi.WSGIHandler()
    

    Once created the WSGI file, create an Apache configuration file named 'projectName.conf' in 'installdir/apps/django/conf' to load it. Please, replace installdir with your installation directory (i.e. "/opt/bitnami") and pythonversion with the Python version (i.e. "python2.7" for Python version 2.7.x).

    Alias /static "installdir/apps/django/lib/pythonversion/site-packages/django/contrib/admin/static"
    
    <Directory 'installdir/apps/django/lib/pythonversion/site-packages/django/contrib/'>
        <IfVersion < 2.3 >
        Order allow,deny
        Allow from all
        </IfVersion>
        <IfVersion >= 2.3>
        Require all granted
        </IfVersion>
    </Directory>
    
    WSGIScriptAlias /URL_mount_point "installdir/apps/django/scripts/projectName.wsgi"
    
    <Directory 'installdir/apps/django/scripts'>
        <IfVersion < 2.3 >
        Order allow,deny
        Allow from all
        </IfVersion>
        <IfVersion >= 2.3>
        Require all granted
        </IfVersion>
    </Directory>
    

    Edit the file 'httpd.conf' and add the following line:

    Include "installdir/apps/django/conf/projectName.conf"
    

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

    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
    DATABASES = {
        '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': '127.0.0.1' .

    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.


    Remove the previous installation to avoid that files from the old version are kept in the system causing problems with the new install. On virtual machines and cloud images you can remove the previous version with the following command:

    sudo rm -rf  /opt/bitnami/apps/django/lib/python2.7/site-packages/*
    

    Download the latest version from https://www.djangoproject.com/download/ and uncompress it.

    On Linux you can download the Django tarball directly to your machine executing the comand below (this is useful for downloading the Django directly to the remote server).

    wget  https://www.djangoproject.com/m/releases/1.6/Django-1.6.5.tar.gz 
    

    If you are upgrading Django in a remote server, you can also download the archive to your local machine and upload it to the remote server trough SFTP with a tool like FileZilla. Then access your server to uncompress the tarball and follow the next steps.

    tar zxvf Django-1.6.5.tar.gz
    
    cd Django-1.6.5
    

    Once the tarball is uncompressed you can execute the command below from the Django-1.6.5 directory.

    On Windows execute:

    python.exe setup.py install  --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 python setup.py install --prefix=/opt/bitnami/apps/django
    


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

    python setup.py install --prefix=/installdir/apps/django
    

     

    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:

    #!/opt/bitnami/python/bin/.python2.7.bin
    

    with

    #!/opt/bitnami/python/bin/python
    
    Tag page (Edit tags)
    • No tags
    Pages that link here
    Page statistics
    50269 view(s), 23 edit(s) and 10302 character(s)

    Comments

    You must login to post a comment.

    Attach file

    Attachments