Django Introduction Example : 1 To test Python Django working Example :2 To display welcome message Example :3 To To Display Students Data In Table Format
Example 2
To display a welcome message
Goto folder e:\django
Step 1: create a project
E:\Django>django-admin startproject firstproject
E:\Django>cd firstproject
E:\Django\firstproject>
Step :2
Create the application
E:\Django\firstproject>python manage.py startapp testapp
Step :3
Now we have to within the project folder (firstproject) and add the application in the settings.py
# Application definition
INSTALLED_APPS = [
‘django.contrib.admin’,
‘django.contrib.auth’,
‘django.contrib.contenttypes’,
‘django.contrib.sessions’,
‘django.contrib.messages’,
‘django.contrib.staticfiles’,
‘testapp’,
]
Step:4
Now goto application folder (testapp) and add a view to display the welcome message
Views.py (in testapp folder)
from django.shortcuts import render
from django.http import HttpResponse
# Create your views here.
def welcome(request):
return HttpResonse(‘<h1>Welcome to Django Project </h1>’)
Step:5
Define urls in urls.py in project related to views defined in views.py in application
Urls.py (in project folder firstproject)
from django.contrib import admin
from django.urls import path
from testapp import views
urlpatterns = [
path(‘admin/’, admin.site.urls),
path(‘welcome/’,views.welcome),
]
Step:6
Run the server so that project can be executed
E:\Django\firstproject>python manage.py runserver
Now put the below address in browser to get the output
Django Introduction Example : 1 To test Python Django working Example :2 To display welcome message Example :3 To To Display Students Data In Table Format