Part 2: Setting up Django, URLs & Views

Continued from Part 1: Setting up Django and virtualenv
Will will add a url to out crudapp. Add the following into urls.py

...
from crudapp import views as home

urlpatterns = [
    ...
    url(r'^$', home.init),
]

This means when we go to the root url http://localhost:8000 we will be directed to views where Django will look for a function or view called init(). Let us create that next. Add the following to crudapp/views.py

def init(request):
    return render(request, 'index.html')

This will direct us to index.html. However, index.html needs to be created in a new folder called templates. Inside the root folder djangoCRUD create templates/index.html

<!DOCTYPE html>
<html lang="en">
<head>

</head>
<body>
  <p>hello forum</p>
</body>

We have not told Django where the templates folder is. Add

os.path.join(BASE_DIR, "templates")

to settings.py like this,

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, "templates")],
....

Part 3: Django CRUD, Display Models