Creating the App
# Navigate to the project folder and create the app
cd myproject
py manage.py startapp 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),
]
- Following message shown at http://127.0.0.1:8000/players/ if everything is alright:
Creating a basic View using Template
- Create a folder named templates and an html file (basic.html) for the template as follows:
<!DOCTYPE html>
<html>
<body>
<h1>Hello World!!!</h1>
<p>This is a very basic template example.</p>
</body>
</html>
- Following message shown at http://127.0.0.1:8000/players/ if everything is alright: