django dynamic pages

Solutions on MaxInterview for django dynamic pages by the best coders in the world

showing results for - "django dynamic pages"
Paul
07 Feb 2016
1# Views.py:
2
3from django.shortcuts import get_object_or_404, render
4
5def render_items(request, item_name):
6    item = get_object_or_404(YOUR_MODEL, YOUR_ITEM_FIELD_NAME=item_name)
7    return render(request, 'YOUR_TEMPLATE.html', {'item': item })
8  
9# Add below line to urlpatterns
10
11    path('items/<str:item_name>/',views.render_items, name='item'),
12  
13# Detail Template
14
15{% extends "main/header.html" %}
16{% block content %}
17<body>
18    <div class="item-detail">
19        <h1> Detail </h1>
20        <p>{{ item.name }}</p>
21    </div>
22</body>
23{% endblock %}