Django Workflow


Create the administrative user to enable logins to the /admin section of the site:

(env)$  python createsuperuser

View & URL

  1. startapp <appname>
  2. add the app to the projects file section:
  3. Create a view to render: edit the <appname> apps file:
    from django.http import HttpResponse
    def index(request):
        return HttpResponse("It works!")
  4. Map the URL for the view: create the <appname>
    from django.conf.urls import patterns, url
    from <appname> import views
    urlpatterns = patterns('',
            url(r'^$', views.index, name='index'))
  5. Update the project’s  file to look for the <appname>’s url in the request
    urlpatterns = patterns('',
        # Examples:
        # url(r'^$', 'tango_with_django_project_17.views.home', name='home'),
        # url(r'^blog/', include('blog.urls')),
        url(r'^admin/', include(,
        url(r'^<appname>/', include('<appname>.urls')), 
  6. Now you can visit <IP>:8080/<appname> to see your view working (do restart the server first via:
    python runserver <IP>:8080 )


Create the directory structure for the app:

  1. create a templates directory in the projects root
  2. inside of the new templates directory create a directory matching the name of your app <appname>
  3. inside of the /projectdir/templates/<appname>/ directory create an index.html file

Update the project

  1. edit the projects file and add the following where <projectname> is the name of the folder that houses the entire project and contains the file:
    TEMPLATE_PATH = os.path.join(BASE_DIR, '<projectname>/templates')
  2. then to the same file add:
        # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
        # Always use forward slashes, even on Windows.
        # Don't forget to use absolute paths, not relative paths.
  3. create a template view in the /projectdir/templates/<appname>/index.html file  eg:
    <!DOCTYPE html>
         <title>Print Consumable Tracking</title>
         <h1>Tracking Printer Consumable Items</h1>
         <strong>{{ boldmessage }}</strong><br />
         <a href="/rango/about/">About</a><br />
  4. in the application’s file add:
    from django.shortcuts import render

    and update the index() to:

    def index(request):
        # Construct a dictionary to pass to the template engine as its context.
        # Note the key boldmessage is the same as {{ boldmessage }} in the template!
        context_dict = {'boldmessage': "I am bold font from the context"}
        # Return a rendered response to send to the client.
        # We make use of the shortcut function to make our lives easier.
        # Note that the first parameter is the template we wish to use.
        return render(request, '<appname>/index.html', context_dict)

Initial Django Setup for itstock project

The following steps assume you’ve completed part 1 :


  1. Re-activate your virtual environment (where /code/env is the location you created the virtualenv)
    $ source ./code/env/bin/activate
  2. cd into the parent directory of the virtualenv (/code/) in this example:
    (env)$ cd ./code
  3. Create the django project named itstock:
    (env)~/code/itstock$ django-admin startproject itstock
  4. Now setup Git on the ./code/itstock directory by:
    (env)~/code/itstock$ git init ./
    (env)~/code/itstock$ git add ./
    (env)~/code/itstock$ git commit
  5. Next setup connection to the Bitbucket remote repository via:
     cd to the core directory of the project:

    (env)~/code/itstock$ cd ./itstock
  6. (env)~/code/itstock/itstock$ git remote add origin<username>/<name of repo>
    (env)~/code/itstock/itstock$ git push -u origin --all
    (env)~/code/itstock/itstock$ git push -u origin
  7. Integrate Bitbucket Git repo to Pycharm: 

    Launch pycharm and select the core directory [~/code/itstock/itstock in my case] as the location for the projectDownload the Bitbucket plugin from Pycharm click : File > Settings > Plugins > Install plugin from disk…

    Then select the downloaded zip file and install.

    I got a bit lost then, you need to add the Bitbucket repo in when you want to push, maybe start with a PULL request to define that and then work from there.

  8. Ensure the db is migrated:
    Back in the terminal:

    (env)~/code/itstock$ python runserver <IP>:8080




















django setup with virtualenv & PyCharm

Setting up my django development (basic).

The following steps assuming that Python is installed.

  1. Setup a repository on Bitbucket:
    Ensure my development machine has access via SSH keys
  2. Install pip on development machine:
    To install pip, securely download
    Then run the following (which may require administrator access):

    $[sudo] python
  3. Install virtualenv on the development machine:

    $ [sudo] pip install virtualenv
  4. Create a working directory for the project:
    $mkdir /path/to/project/root
  5. Create the virtual environment to work from:
    $virtualenv /path/to/project/root/env
  6. Activate the virtual environment:
    $source /path/to/project/root/env/bin/activate
  7. Install mysql-python:
    (env)$[sudo]apt-get install python-dev libmysqlclient-dev
    (env)$pip install MySQL-python
  8. Install django 1.7:
    (env)$pip install django==1.7

    exit the virtualenv for now by:

    (env)$ deactivate
  9. Install pycharm to manage the project from a GUI:
    First install java:

    $ sudo add-apt-repository ppa:webupd8team/java
    $ sudo apt-get update
    $ sudo apt-get install oracle-java8-installer
    $ sudo apt-get install oracle-java8-set-default

    Next install pycharm:

    Download from
    or from a directory outside of your project directory:

    $ wget

    change to that directory and :

    $ tar -xvf pycharm-community-4.5.3.tar.gz

    now to launch pycharm:

    $ ./pycharm-community-4.5.3/bin/


Django 1.7, mysql-python and the pycharm editor should now be ready to use!


Next: Setting up the itstock django project