Browser wont display my site


#1

Hello,

I am just getting started with the training and it looks like have a issue with my coding already, I managed to install python an django ok with a page displayed as per the book (the it Works Page)

next i add the index.html, the url.py and the views.py entries but now when the page is displayed it show this error, I am sure i am not the first to get this but the search did not show any results

expected an indented block (views.py, line 6)


#2

Check the formatting of your code — that error means that something has the wrong indentation. :) Line 6 specifically.


#3

Yeah that was my initial thought, was a cut and paste from the book


#4

Unfortunately when InDesign outputs the book files, it loses formatting information so you got to go in and fix the formatting. :(


#5

This a simple fix all i needed to do was to add a tab in front of the second line of code, can anyone comment as to the reason for the needed space at the beginning of the line?

still learning


#6

Sure thing! It’s because that’s how Python determines the order of code. It’s like a headline and content:

Headline
Content

We know the above is a headline because it’s bold. Python uses indentation:

headline
    content

So the indented block tells Python that it’s basically the content under the header.

If you haven’t done so already, I’d suggest going through some of Learn Python the Hard Way which’ll explain how to work with Python. :)