How to learn Django without installing anything

Posted in:

Here is way of learning to create a website using the Django web framework without having to install anything on your local computer.

This might be useful if:

  • you are intimidated by all the hurdles you need just to get to the beginning of the tutorial.

  • you can't install things on your own computer.

  • or you want to be able to carry on with the learning from a different computer, without copying your progress or installing things on the other computer.

Prerequisites

  • I'm assuming you already know how to program in Python, or are sufficiently experienced with programming that you don't mind learning Python while learning Django at the same time. If not, have a look at these starting points:

    If you don't know much about programming, try Learn Python The Hard Way.

    If you are experienced with other programming languages, but not Python, try, Dive Into Python.

  • I'm assuming you are reasonably comfortable with typing things into a command prompt or terminal. Thankfully, even if you are not, you'll be doing everything in a virtual machine somewhere on the internet, so you can't break anything!

Steps

  • Go to http://code.runnable.com/ and sign up for an account.

  • Create a new project, choosing ‘Django’.

  • You'll be presented with an almost empty Django project, complete with a terminal. You can browse and edit files, and types commands at the terminal, and press the big green 'Run' button to run your site and view pages in another tab.

    However, we first want to remove some things so that we can follow the Django tutorial exactly.

    In the terminal, type the following commands and hit enter. First, delete all the files created in /var/www:

    rm -rf /var/www/*
    

    Next, we need to upgrade Django, because runnable.com installed an old version:

    pip install --upgrade Django
    
  • Now, open up the Django docs and start the tutorial, from part 1:

    https://docs.djangoproject.com/

Adjustments

Because you are running on runnable.com, rather than your own computer, you'll need to make some very slight adjustments to the instructions at certain places:

  • Ignore the comment about not putting files in /var/www – while it should be followed in general, it will make it hard for you to edit files on code.runnable.com if you put them outside /var/www.

  • After you have run startproject in the tutorial, you will need to find the settings.py file and make an adjustment. Find the block that defines MIDDLEWARE_CLASSES and remove the line:

    'django.middleware.clickjacking.XFrameOptionsMiddleware',
    

    This middleware is an important security feature, but it interferes with the way that runnable.com displays your project in a frame (in its normal workflow), and without this change you will be presented with a blank page after you press 'Run'.

  • When it comes to running the your Django project, the easiest way is if you use the green 'Run' button, but adjust the command. Click on the gear icon to configure it, and change the command to:

    cd /var/www/mysite; python manage.py runserver 0.0.0.0:80

    Now press the 'Run' button.

And that's it! You should be able to complete the tutorial with these adjustments.

What next?

I hope this has been helpful! Please comment with any corrections.

To go further, you'll probably want to have a look at Getting started with Django.

Comments §

Comments should load when you scroll to here...