Skip to main content
Redhat Developers  Logo
  • AI

    Get started with AI

    • Red Hat AI
      Accelerate the development and deployment of enterprise AI solutions.
    • AI learning hub
      Explore learning materials and tools, organized by task.
    • AI interactive demos
      Click through scenarios with Red Hat AI, including training LLMs and more.
    • AI/ML learning paths
      Expand your OpenShift AI knowledge using these learning resources.
    • AI quickstarts
      Focused AI use cases designed for fast deployment on Red Hat AI platforms.
    • No-cost AI training
      Foundational Red Hat AI training.

    Featured resources

    • OpenShift AI learning
    • Open source AI for developers
    • AI product application development
    • Open source-powered AI/ML for hybrid cloud
    • AI and Node.js cheat sheet

    Red Hat AI Factory with NVIDIA

    • Red Hat AI Factory with NVIDIA is a co-engineered, enterprise-grade AI solution for building, deploying, and managing AI at scale across hybrid cloud environments.
    • Explore the solution
  • Learn

    Self-guided

    • Documentation
      Find answers, get step-by-step guidance, and learn how to use Red Hat products.
    • Learning paths
      Explore curated walkthroughs for common development tasks.
    • Guided learning
      Receive custom learning paths powered by our AI assistant.
    • See all learning

    Hands-on

    • Developer Sandbox
      Spin up Red Hat's products and technologies without setup or configuration.
    • Interactive labs
      Learn by doing in these hands-on, browser-based experiences.
    • Interactive demos
      Click through product features in these guided tours.

    Browse by topic

    • AI/ML
    • Automation
    • Java
    • Kubernetes
    • Linux
    • See all topics

    Training & certifications

    • Courses and exams
    • Certifications
    • Skills assessments
    • Red Hat Academy
    • Learning subscription
    • Explore training
  • Build

    Get started

    • Red Hat build of Podman Desktop
      A downloadable, local development hub to experiment with our products and builds.
    • Developer Sandbox
      Spin up Red Hat's products and technologies without setup or configuration.

    Download products

    • Access product downloads to start building and testing right away.
    • Red Hat Enterprise Linux
    • Red Hat AI
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform
    • See all products

    Featured

    • Red Hat build of OpenJDK
    • Red Hat JBoss Enterprise Application Platform
    • Red Hat OpenShift Dev Spaces
    • Red Hat Developer Toolset

    References

    • E-books
    • Documentation
    • Cheat sheets
    • Architecture center
  • Community

    Get involved

    • Events
    • Live AI events
    • Red Hat Summit
    • Red Hat Accelerators
    • Community discussions

    Follow along

    • Articles & blogs
    • Developer newsletter
    • Videos
    • Github

    Get help

    • Customer service
    • Customer support
    • Regional contacts
    • Find a partner

    Join the Red Hat Developer program

    • Download Red Hat products and project builds, access support documentation, learning content, and more.
    • Explore the benefits

Using RHSCL: Django on Python 3 with PostgreSQL

June 24, 2013
Bohuslav Kabrda
Related topics:
LinuxPython
Related products:
Red Hat Enterprise Linux

    This article will show you how to use two software collections of RHSCL 1.0 Beta for cutting edge development. We will create a Django 1.5 application (running on Python 3.3), that will use PostgreSQL 9.2 as a database.

    Installing Dependencies

    First off, we will install the required collections. If you haven't done so already, you need to subscribe to the correct RHN channel (rhel-x86_64-variant-6-rhscl-1-beta, where variant is one of server, client or workstation).

    Now you should be able to install all the needed dependencies just by issuing this command (as a superuser):

    yum install python33 postgresql92 python33-python-psycopg2

    The reason why python33-python-psycopg2 has to be listed is that it doesn't belong to the basic python33 installation package set.

    Configuring PostgreSQL

    Now we need to setup a PostgreSQL database. First, let's initialize database cluster and run the service (as a superuser):

    service postgresql92-postgresql initdb
    service postgresql92-postgresql start

    Second, we need to create the actual database. For this, we have to switch to postgres user, who has permissions to do this, then we need to create new database user (name should be the same as the name of your local account) and then finally the database called testdb (again, do this as a superuser):

    su - postgres
    scl enable postgresql92 bash
    createuser
    createdb testdb --owner

    We're all set and we can continue with the Django part. Before going on, don't forget to exit the all the subshells to get back to your original shell.

    Creating a New Django Project

    We will create a new Django project using virtualenv. Everything we need (except for Django itself) is present in the python33 collection, so we just need to create the virtual environment and install Django from PyPi there:

    scl enable python33 postgresql92 bash
    virtualenv --system-site-packages my-django-app
    cd my-django-app
    source bin/activate
    pip install django==1.5.1

    To comment a bit on the above:  First we switch to SCL-enabled shell (don't forget to enable both collections), then we create a virtualenv directory my-django-app (passing the option to use RPM installed site-packages from the collection). After that, we switch to the newly created directory and activate the virtual environment (lines 3 and 4). Finally, we install Django (I decided to pin it to version 1.5.1 in this example, but you should be able to use any version >=1.5.0.)

    Now that everything is set, we can create the actual Django project:

    django-admin.py startproject myproj
    cd myproj

    Then we will adjust database settings to use our previously created database. In your favourite text editor, open myproj/settings.py and fill in database engine, user and name, so that the DATABASES section looks like this:

    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.postgresql_psycopg2',
            'NAME': 'testdb',
            'USER': '',
            'PASSWORD': '',
            'HOST': '',
            'PORT': '',
        }
    }

    ... and then run

    python manage.py syncdb

    to make sure that the database is set correctly. You will be asked whether or not you want to create a new superuser for your project - feel free to choose either option, it doesn't matter for this tutorial.
    And that's it! We now have a fully operational Django 1.5 application running on Python 3.3, using PostgreSQL 9.2 - all that on RHEL 6. Now we can just create a simple view that will print out all this.

    A Simple View to Prove It

    As an optional step, we will create a really minimalistic view that confirms we're using the right versions. First, let's define a new view function. Create a new file myproj/views.py and copy&paste this into it:

    import sys
    
    import django
    
    from django.db import backend, connection
    from django.shortcuts import render_to_response
    
    def index(request):
        return render_to_response('index.html',
                                  {'sysver': sys.version,
                                   'djangover': django.VERSION,
                                   'pgsqlver': backend.get_version(connection)})

    Then create a directory myproj/templates and a file myproj/templates/index.html (note, that we will not use actual HTML, but just a plain text to render the versions, which suites our example but would otherwise be considered very ugly):

    Python: {{ sysver }}, Django: {{ djangover }}, PostgreSQL: {{ pgsqlver }}

    Now we need to tell Django where to look for templates. Find TEMPLATE_DIRS constant in myproj/settings.py and replace it with following:

    import os
    BASE_DIR = os.path.dirname(os.path.abspath(__file__))
    TEMPLATE_DIRS = (
        os.path.join(BASE_DIR, 'templates'),
    )

    Finally, let's route the / (root URL of our Django project) to the newly created view. Open myproj/urls.py in your favourite editor and insert following line into patterns:

    url(r'^$', 'myproj.views.index', name='home')

    Now just run python manage.py runserver and go to http://127.0.0.1:8000/ in your browser. You should see a result like this:
    Python: 3.3.2 (default, Jun 12 2013, 11:40:18) [GCC 4.4.7 20120313 (Red Hat 4.4.7-3)], Django: (1, 5, 1, 'final', 0), PostgreSQL: 90204

    Last updated: February 24, 2024

    Recent Posts

    • Trusted software factory: Building trust in the agentic AI era

    • Build a zero trust AI pipeline with OpenShift and RHEL CVMs

    • Red Hat Hardened Images: Top 5 benefits for software developers

    • How EvalHub manages two-layer Kubernetes control planes

    • Tekton joins the CNCF as an incubating project

    Red Hat Developers logo LinkedIn YouTube Twitter Facebook

    Platforms

    • Red Hat AI
    • Red Hat Enterprise Linux
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform
    • See all products

    Build

    • Developer Sandbox
    • Developer tools
    • Interactive tutorials
    • API catalog

    Quicklinks

    • Learning resources
    • E-books
    • Cheat sheets
    • Blog
    • Events
    • Newsletter

    Communicate

    • About us
    • Contact sales
    • Find a partner
    • Report a website issue
    • Site status dashboard
    • Report a security problem

    RED HAT DEVELOPER

    Build here. Go anywhere.

    We serve the builders. The problem solvers who create careers with code.

    Join us if you’re a developer, software engineer, web designer, front-end designer, UX designer, computer scientist, architect, tester, product manager, project manager or team lead.

    Sign me up

    Red Hat legal and privacy links

    • About Red Hat
    • Jobs
    • Events
    • Locations
    • Contact Red Hat
    • Red Hat Blog
    • Inclusion at Red Hat
    • Cool Stuff Store
    • Red Hat Summit
    © 2026 Red Hat

    Red Hat legal and privacy links

    • Privacy statement
    • Terms of use
    • All policies and guidelines
    • Digital accessibility

    Chat Support

    Please log in with your Red Hat account to access chat support.