Django Simple Coding Notes
Django Simple Coding Notes
App: A Django app is a web application that performs a speci c task within a project. You can
create an app using:
Settings.py
3. Views
Views handle the logic behind web pages and send back responses (HTML, JSON, etc.). A basic
view looks like this:
def home(request):
App urls.py
urlpatterns = [
path('', home),
]
Here's a brief overview of simple concepts in Django to help you get started:
1. What is Django?
Django is a high-level Python web framework that promotes rapid development and clean,
pragmatic design. It follows the Model-View-Template (MVT) architecture, which is similar to the
MVC (Model-View-Controller) pattern.
• App: A Django app is a web application that performs a speci c task within a project. You
can create an app using:
bash
Copy code
3. Views
Views handle the logic behind web pages and send back responses (HTML, JSON, etc.). A basic
view looks like this:
python
Copy code
from django.http import HttpResponse
def home(request):
return HttpResponse("Hello, Django!")
To map this view to a URL, modify urls.py:
python
Copy code
from django.urls import path
from .views import home
urlpatterns = [
path('', home),
]
4. Templates
fi
fi
Templates de ne the HTML structure of your web pages. You can pass data from views to
templates. First, create a templates directory and an HTML le:
def home(request):
context = {'message': 'This is a Django tutorial'}
return render(request, 'home.html', context)
fi
fi