KEMBAR78
Web Dev Using Django | PDF
0% found this document useful (0 votes)
5 views2 pages

Web Dev Using Django

This document provides a step-by-step guide on creating a web development project using Django in Python. It covers installation, project creation, running a development server, creating an app, and setting up views and URLs. Key commands for each step are also summarized for quick reference.

Uploaded by

Anurag kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views2 pages

Web Dev Using Django

This document provides a step-by-step guide on creating a web development project using Django in Python. It covers installation, project creation, running a development server, creating an app, and setting up views and URLs. Key commands for each step are also summarized for quick reference.

Uploaded by

Anurag kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

WEB DEVELOPMENT IN PYTHON USING DJANGO

How to Create a Project in Django

✅ Step-by-Step:

🔹 Step 1: Install Django


Make sure Python is installed (version 3.8+ recommended). Then install Django
using pip:
pip install django
Check version:
django-admin --version

🔹 Step 2: Create a New Django Project


Use django-admin to start a new project. Replace myproject with your desired
project name:
django-admin startproject myproject
This creates a folder like this:
myproject/
manage.py
myproject/
__init__.py
settings.py
urls.py
asgi.py
wsgi.py

🔹 Step 3: Navigate to Your Project Directory


cd myproject

🔹 Step 4: Run the Development Server


python manage.py runserver
Visit in browser:
http://127.0.0.1:8000/
You should see the default “It worked!” Django page.

🔹 Step 5: Create a Django App


Each project can have multiple apps (modules). Let’s create an app called blog:
python manage.py startapp blog
Folder structure:
blog/
admin.py
apps.py
models.py
views.py
tests.py
...

🔹 Step 6: Add the App to settings.py


Open myproject/settings.py, and add 'blog' to the INSTALLED_APPS list:
INSTALLED_APPS = [
...
'blog',
]

🔹 Step 7: Create a Simple View


In blog/views.py:
from django.http import HttpResponse

def home(request):
return HttpResponse("Hello, Django!")

🔹 Step 8: Map the View to a URL


In blog/urls.py (create this file if it doesn't exist):
from django.urls import path
from . import views

urlpatterns = [
path('', views.home, name='home'),
]
Then include this blog.urls file in the main urls.py (in myproject/urls.py):
from django.contrib import admin
from django.urls import path, include

urlpatterns = [
path('admin/', admin.site.urls),
path('', include('blog.urls')), # This links your app
]

🔹 Step 9: Run the Server Again


python manage.py runserver
Visit http://127.0.0.1:8000/ → You should see:
“Hello, Django!”

✅ Summary Commands:
pip install django
django-admin startproject myproject
cd myproject
python manage.py startapp blog
# Edit settings.py to add 'blog'
# Add URLs and views
python manage.py runserver

You might also like