Base, list and detail views - Django Online Store - 06
Next step, once you have registered your application and migrations
We have created the base views or master template, so let's create it:
mystore\elements\templates\base.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Django</title>
</head>
<body>
{% block content %}
{% endblock %}
{% block footer %}
<footer>
<p>2025 - All rights reserved</p>
</footer>
{% endblock %}
</body>
</html>
This is the one that will use the list and detail:
mystore\elements\views.py
from django.shortcuts import render
# Create your views here.
def index(request):
return render(request,'elements/index.html')
def detail(request, pk):
return render(request,'elements/detail.html')
For now, we only want its structure, we want to work little by little so that we can define the structure here:
Its views:
mystore\elements\views.py
{% extends "base.html" %}
{% block content %}
Index
{% endblock %}
We create the view and its template for the detail of the products of type:
mystore\elements\views.py
{% extends "base.html" %}
{% block content %}
Detail
{% endblock %}
And the routes:
mystore\elements\urls.py
from django.urls import path
from . import views
urlpatterns = [
path('', views.index, name='index'),
path('<int:pk>', views.detail, name='detail'),
]
mystore\mystore\urls.py
urlpatterns = [
path('admin/', admin.site.urls),
path('store/', include('elements.urls')),
]