Skip to content

Instantly share code, notes, and snippets.

@prodeveloper
Last active September 13, 2018 20:54
Show Gist options
  • Save prodeveloper/e5264f48d256998b8b880ef1d4ff988e to your computer and use it in GitHub Desktop.
Save prodeveloper/e5264f48d256998b8b880ef1d4ff988e to your computer and use it in GitHub Desktop.
Installing Django on Cloud 9

In today's lesson we are going to look at installing django to cloud9.

Django is a web framework that will enable us to quickly write and deploy our web apps.

It's homepage defines it as:

    Django is a high-level Python Web framework that encourages rapid development and clean, pragmatic design. Built by experienced developers, it takes care of much of the hassle of Web development, so you can focus on writing your app without needing to reinvent the wheel.

Typically installations can be a bit painful involving setting up django and python involves a series of steps. Specifically

  • Install Python
  • Install pip
  • Install virtualenv
  • Finally install Django

Thankfully with cloud9 we jump most of this steps.

Let us start

##Step 1

We start by creating a new workspace. You may remember that we had done this for the project that we now use in class.

This will lead you to the page where you select your project settings. Select to build a django workspace.

You can use a description that makes the most sense to you.

##Step 2

Cloud 9 should take care of all the hardwork of setting up your environment.

The file structure will look as follows.

Once this is done try to run the project to see what you get. The button isa menu item on top of the page.

You should be able to see a welcome to django page.

By default, c9 uses Python 2.7. We need to change it to use python 3.

Run the following commands on your bash

sudo mv /usr/bin/python /usr/bin/python2 
sudo ln -s /usr/bin/python3 /usr/bin/python 
sudo pip install django 

This commands will do the following respectively:

  1. Move the shortcut for python to a different file
  2. Make python3 the default
  3. Install django using python3

##Step 3

Now we can go right ahead and create our first app. We do this by running the command.

python manage.py startapp firstapp

Now run the app once more. You should see an error message.

All you need to do is now add the host to your hosts file. Eg mine is ‘akirachix-2017-django-prodeveloper.c9users.io'. Copy that to your allowed hosts in settings.py

Save the file and run the project once more. This time, you should once more see the homepage.

##Step 4

Django comes with a free admin panel preinstalled. To use it, we first must create a super user.

On the terminal, type the following command:

python manage.py createsuperuser

With the password you created, you can now login to the admin panel on the webpage.

The admin panel is found by adding /admin to the end of your url. For example mine is

https://akirachix-2017-django-prodeveloper.c9users.io/admin

You should see the login page.

Put in the username and password you just created to login.

For now there is not much in the admin page, but this will change as we add more things.

##Assignment

For your assignment. Run through the process above to create a new and different workspace.

Create a new user in your admin panel and see if you can login with that user's credentials.

##Links

@panpawn
Copy link

panpawn commented Sep 13, 2018

Hi, for some reason, when I add my c9 link host thing to ALLOWED_HOSTS in settings.py, it still isn't working and I'm still getting that screen when I go to it.

Any ideas?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment