Django Skeleton App

Django skeleton app is an app with only necessary and sufficient features to showcase the django reuqest response cycle. A simple Hello world text will be shown on the screen when the homepage is requested.

New Django Project & App

To get started with the skeleton project or the hello world project we must have python and django installed. Here is a quick recap of all pre-requisites: /p>

To install Django LTS version 2.2:

    pip install django==2.2
                                

To verify django version:

    django-admin --version
                                

To start new project:

    django-admin startproject mysite
    cd mysite
    python manage.py migrate
                                

To start new app

    python manage.py startapp myapp
                                

Below we have the code from each necessary module.

mysite : setting.py

    INSTALLED_APPS = [
        'django.contrib.admin',
        'django.contrib.auth',
        'django.contrib.contenttypes',
        'django.contrib.sessions',
        'django.contrib.messages',
        'django.contrib.staticfiles',
        'myapp',
    ]   
                                

mysite : urls.py

    from django.contrib import admin
    from django.urls import path, include
    
    urlpatterns = [
        path('admin/', admin.site.urls),
        path('myapp/', include('myapp.urls'))
    ]
                                

myapp : urls.py

The urls.py module has to be created manually, under myapp directory.

    from django.urls import path
    from . import views 
    
    urlpatterns = [
        path('', views.index)
    ]
                                

myapp : views.py

    from django.shortcuts import render
    
    def index(request):
    	return render(request, 'index.html', {})
                                

mysite : templates : index.html

The templates directory has to be created manually, under myapp directory. Then then index.html is also maually put under the templates directory.

    Hello World
                                

Django runserver

Finally, run the developent server and visit localhost on port 8000.

    python manage.py runserver
                                

And in you favourite web browser open url:

    127.0.0.1:8000/myapp/
                                
Django hello world project