Django Starter 2 — Create App

Rubaiyat Rahim
2 min readMay 20, 2024

--

Creating a basic app in an existing Django project and adding basic views in it.

Other parts of this series: Part 1 | Part 3 | Part 4 | Part 5 | Part 6

Creating the App

# Navigate to the project folder and create the app
cd myproject
py manage.py startapp players
File system contents in the app folder (projectroot/myproject/players).

Registering the new App

Add the name of the app in the INSTALLED_APPS list in projectroot/myproject/settings.py file as follows:

...

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

'players',
]

...

Creating a basic Hello World View

  • Add the view in projectroot/myproject/players/views.py as follows:
from django.shortcuts import render
from django.http import HttpResponse

def players(request):
return HttpResponse("Hello world!!!")
  • Set the URL in the app folder by creating a new file urls.py there as follows: (projectroot/myproject/players/urls.py)
from django.urls import path
from . import views

urlpatterns = [
path('players/', views.players, name='players'),
]
  • Set the URL in the project folder as follows: (projectroot/myproject/urls.py)
from django.contrib import admin
from django.urls import include, path

urlpatterns = [
path('', include('players.urls')),
path('admin/', admin.site.urls),
]
Output of the basic Hello World view.

Creating a basic View using Template

  • Create a folder named templates and an html file (basic.html) for the template as follows:
The basic template file in the (app)/templates folder.
<!DOCTYPE html>
<html>
<body>

<h1>Hello World!!!</h1>
<p>This is a very basic template example.</p>

</body>
</html>
Output of the basic template view.

--

--