Creating first Django Project (Hello World in Django)

How to create "Hello world" program in django.

Creating a “Hello, World!” application in Django is a simple process. Django is a Python web framework that allows you to build powerful web applications quickly and efficiently. Here’s a step-by-step guide to creating a basic “Hello, World!” Django application:

  1.  
  2.  
  3. 1. Install Django: Make sure you have Python installed on your system. You can then install Django using pip, the Python package manager, by running the following command in your terminal or command prompt:
				
					pip install django
				
			

 

 

2. Create a new Django project: Create a new Django project by running the following command in your terminal or command prompt:

				
					django-admin startproject helloworldproject

				
			

This will create a new directory named helloworldproject with the necessary project structure.

 

 

3. Navigate to the project directory: Change into the newly created project directory:

				
					cd helloworldproject

				
			

 

 

 

4. Create a Django app: Django projects are made up of one or more apps. To create a new app named helloworldapp, run the following command:

				
					python manage.py startapp helloworldapp

				
			

5. Configure URLs: Open the file helloworldproject/urls.py and add a URL pattern to map the hello_world view to the root URL of the project:

				
					from django.contrib import admin
from django.urls import path
from helloworldapp.views import hello_world

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', hello_world, name='hello_world'),
]

				
			

 

 

6. Define a view:

Open the file helloworldapp/views.py and define a simple view function that will return “Hello, World!” as the response:

				
					from django.http import HttpResponse

def hello_world(request):
    return HttpResponse("Hello, World!")

				
			

 

 

7. Run the development server: Now, you can start the development server using the following command:

 

				
					python manage.py runserver

				
			

8. Access the application: Open your web browser and go to http://127.0.0.1:8000/. You should see “Hello, World!” displayed on the page.

Comments are closed.

Tech Amplifier Final Logo