DJANGO PROJECT:
HELLO WORLD
Step-by-Step Guide to Create a Simple Django App
1. ACTIVATE THE VIRTUAL
ENVIRONMENT
• Open terminal and run:
• On Windows:
venv_nameScriptsactivate
• On macOS/Linux:
source venv_name/bin/activate
2. CREATE DJANGO PROJECT
• Run the following command:
• django-admin startproject hello_project
• cd hello_project
• This creates the project folder.
3. PROJECT STRUCTURE
• hello_project/
├ manage.py
└ hello_project/
├ __init__.py
├ asgi.py
├ settings.py
├ urls.py
└ wsgi.py
4. CREATE DJANGO
APP
RUN THE COMMAND:
python manage.py startapp
hello_app
• This creates the `hello_app` folder.
• hello_project/
• ├ hello_app/
• │ ├ migrations/ # Database migrations
• │ ├ __init__.py
• │ ├ admin.py # Admin interface settings
• │ ├ apps.py # App configuration
• │ ├ models.py # Database models
• │ ├ tests.py # Test cases
• │ └ views.py # App logic (where we'll add Hello
World)
3. PROJECT STRUCTURE
• hello_project/
├ manage.py
└ hello_project/
├ __init__.py
├ asgi.py
├ settings.py
├ urls.py
└ wsgi.py
5. UPDATE
SETTINGS.PY
In Hello_project/Settings.Py,
Add 'Hello_app' In
INSTALLED_APPS:
• INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'hello_app', # Add this line
]
6. CREATE
HELLO
WORLD VIEW
• In `hello_app/views.py, add:
• from django.http import
HttpResponse
def hello_world(request):
return HttpResponse("Hello,
World!")
7. CONFIGURE URLS
Explanation
• admin: Imports the Django admin
site functionality.
• path: Used to define URL patterns.
• include: Allows including app-level
urls.py in the project’s urls.py
In `hello_project/urls.py` include the
app URLs:
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path(‘ ', include('hello_app.urls')), #
Add this line
]
7. CONFIGURE URLS
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path(‘ ', include('hello_app.urls')), # Add this line
]
Explanation:
• path('admin/', admin.site.urls)
• Routes /admin/ to the Django admin panel.
• path(‘ ', include('hello_app.urls'))
• Routes the root URL (/) to the hello_app app.
• The include() function links to
hello_app/urls.py.
• Example: If you visit http://127.0.0.1:8000/,
Django will look for the URL patterns inside
hello_app/urls.py.
8. RUN THE
SERVER
Apply migrations and
start server:
python manage.py
migrate
python manage.py
runserver
Visit:
http://127.0.0.1:8000/
to see 'Hello,World!'

django ppt for which shows hello world in the server

  • 1.
    DJANGO PROJECT: HELLO WORLD Step-by-StepGuide to Create a Simple Django App
  • 2.
    1. ACTIVATE THEVIRTUAL ENVIRONMENT • Open terminal and run: • On Windows: venv_nameScriptsactivate • On macOS/Linux: source venv_name/bin/activate
  • 3.
    2. CREATE DJANGOPROJECT • Run the following command: • django-admin startproject hello_project • cd hello_project • This creates the project folder.
  • 4.
    3. PROJECT STRUCTURE •hello_project/ ├ manage.py └ hello_project/ ├ __init__.py ├ asgi.py ├ settings.py ├ urls.py └ wsgi.py
  • 5.
    4. CREATE DJANGO APP RUNTHE COMMAND: python manage.py startapp hello_app • This creates the `hello_app` folder. • hello_project/ • ├ hello_app/ • │ ├ migrations/ # Database migrations • │ ├ __init__.py • │ ├ admin.py # Admin interface settings • │ ├ apps.py # App configuration • │ ├ models.py # Database models • │ ├ tests.py # Test cases • │ └ views.py # App logic (where we'll add Hello World)
  • 6.
    3. PROJECT STRUCTURE •hello_project/ ├ manage.py └ hello_project/ ├ __init__.py ├ asgi.py ├ settings.py ├ urls.py └ wsgi.py 5. UPDATE SETTINGS.PY In Hello_project/Settings.Py, Add 'Hello_app' In INSTALLED_APPS: • INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'hello_app', # Add this line ]
  • 7.
    6. CREATE HELLO WORLD VIEW •In `hello_app/views.py, add: • from django.http import HttpResponse def hello_world(request): return HttpResponse("Hello, World!")
  • 8.
    7. CONFIGURE URLS Explanation •admin: Imports the Django admin site functionality. • path: Used to define URL patterns. • include: Allows including app-level urls.py in the project’s urls.py In `hello_project/urls.py` include the app URLs: from django.contrib import admin from django.urls import path, include urlpatterns = [ path('admin/', admin.site.urls), path(‘ ', include('hello_app.urls')), # Add this line ]
  • 9.
    7. CONFIGURE URLS fromdjango.contrib import admin from django.urls import path, include urlpatterns = [ path('admin/', admin.site.urls), path(‘ ', include('hello_app.urls')), # Add this line ] Explanation: • path('admin/', admin.site.urls) • Routes /admin/ to the Django admin panel. • path(‘ ', include('hello_app.urls')) • Routes the root URL (/) to the hello_app app. • The include() function links to hello_app/urls.py. • Example: If you visit http://127.0.0.1:8000/, Django will look for the URL patterns inside hello_app/urls.py.
  • 10.
    8. RUN THE SERVER Applymigrations and start server: python manage.py migrate python manage.py runserver Visit: http://127.0.0.1:8000/ to see 'Hello,World!'