Difficulty: beginner
Estimated Time: 15 minutes

Writing your first Django app, part 1

This walks through the Django documentation for writing your first app using Theia as the IDE

The docs for this guide are hosted on the Django site here

You've completed your first Katacoda scenario!

Don’t stop now! The next scenario will only take about 10 minutes to complete.

Django tutorial with Thiea

Step 1 of 3

Step 1 - Setup Django

Setting up Django

Task

First we'll setup pipenv and then run those commands in that shell

We'll run these commands in the tutorial directory: cd /home/scrapbook/tutorial

Install pipenv: pip install pipenv

Open the available shell: pipenv shell

Install Django: pipenv install django

Once Django is installed we can use it to generate a project structure for us. This time we'll create it in the Theia project directory: cd /home/project/ django-admin startproject mysite /home/project

Ok, try and run the project. We'll start the server in a separate terminal so we can leave it running.

We're running in a virtual shell so we need to open that env in the 2nd terminal then start the server: cd /home/scrapbook/tutorial pipenv shell

cd /home/project/ python manage.py runserver 0.0.0.0:8000

If you want to shut it down, just use: control + c

Can you see it?

Django Welcome Screen: https://[[HOST_SUBDOMAIN]]-8000-[[KATACODA_HOST]].environments.katacoda.com

Probably not...

You probably see something like this:

DisallowedHost at /
Invalid HTTP_HOST header:...

So let's update the ALLOWED_HOSTS setting.

Open the Theia editor in the IDE tab

In your project settings.py file,set ALLOWED_HOSTS to this (line 28) :

ALLOWED_HOSTS = ['[[HOST_SUBDOMAIN]]-8000-[[KATACODA_HOST]].environments.katacoda.com', '[[HOST_IP]]']

Now can you see it?

Django Welcome Screen: https://[[HOST_SUBDOMAIN]]-8000-[[KATACODA_HOST]].environments.katacoda.com