Python Forum
<title> django page title dynamic and other field (not working)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
<title> django page title dynamic and other field (not working)
#1
Hello , my name luigi from italy age 39 old year .. my studing hobby web programming for django web framework.
my problem not work in template <title>blcok code and other row.

only model photo .. not working model Album in album_detail.html

showing :

{{album.title}}

idea? how to fixed ?? django 3.2

"""
album.html 
"""
{% extends "site/common.album.html" %}
{% load static %}
{% block title %} Album {% endblock %}
{% block content %}
<div class="row" >
{% for albumData in album  %}
  <div class="col-sm-4"  style="padding-top:30px;">
    <div class="card"> 
      <div class="card-body">
        <h5 class="card-title">{{albumData.titolo }}</h5>
        <p class="card-text">{{albumData.descrizione }}</p>
        <a href="{{albumData.id }}/">Accedi</a>
      </div>
    </div>
  </div>
{% empty %}
<div>No album</div>
{% endfor %}
</div>
 
{% endblock content %}
 
""" 
album_detail.html 
"""
 
{% extends "site/common.photo.html" %}
{% load static %}
 
{% block title %} Foto {% endblock title %}
{% block content %}
<h1 class="display-1 text-center">Foto</h1>
<h3>{{album.titolo}}</h3>
<div id="photo">
          <ul class="album album_1">
            {% for photoData in photo %}
            <li><figure class="figure">
              <a href="/public/{{photoData.foto.large }}" class="big"><img src="/public/{{photoData.foto.thumbnail }}" class="figure-img img-fluid rounded big" alt="{{photoData.titolo }}" title="{{photoData.descrizione }}"></a>
              <figcaption class="figure-caption text-center">{{photoData.descrizione }}</figcaption>
            </figure>
          </li>
          {% empty %}
          <div>No photo</div>
          {% endfor %}
        </ul>  
</div>
</div>
{% endblock content %}

"""
views.py
"""
from django.shortcuts import render
from .models import Album, Photo
 
def view_album(request):
    album = Album.objects.all().order_by('creato')
    context = {'album': album}
    return render(request, "album.html", context)
 
def view_photo(request, album_id):
    photo = Photo.objects.filter(album_id=album_id).all().order_by('creato')
    context = {'photo': photo}
    return render(request, "album_detail.html", context)
Reply
#2
Problem solved.

views.py
def view_album(request):
    album = Album.objects.all().order_by('creato')
    return render(request, 'album.html', {'album': album})


def view_photo(request,  album_slug):
    photo = Photo.objects.filter(album__slug=album_slug)
    album = Album.objects.filter(slug=album_slug).order_by('creato')
    return render(request, 'album_detail.html', {'photo': photo, 'album': album})
models.py
from django.db import models
from django.utils.text import slugify
from django.urls import reverse
STATO = (
    (0,"Bozza"),
    (1,"Publico")
)

class Pages(models.Model):

    id = models.AutoField(primary_key=True)
    autore = models.ForeignKey(
        "auth.User",
        on_delete=models.CASCADE,
    )
    titolo = models.CharField(max_length=255)
    slug = models.SlugField(max_length=255, unique=True)
    contenuto = models.TextField()
    stato = models.IntegerField(choices=STATO, default=0)
    creato = models.DateTimeField(auto_now_add=True)
    modificato = models.DateTimeField(auto_now= True)

    def __str__(self):
        return self.titolo

    def get_absolute_url(self):
        return reverse('pages', kwargs={"id": self.id,'slug': self.slug})
        
    def save(self, *args, **kwargs):
        self.slug = slugify(self.titolo)
        super().save(*args, **kwargs)
        
    class Meta:
        ordering = ['-creato']
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Not getting Info(Title) yrstruly 1 1,722 Jan-25-2023, 10:24 PM
Last Post: snippsat
  Parsing html page and working with checkbox (on a captcha) straannick 17 11,038 Feb-04-2021, 02:54 PM
Last Post: snippsat
  Getting a list in dynamic page probottpric 1 1,746 Oct-12-2020, 01:11 AM
Last Post: Larz60+
  css not working in Django mp3909 3 3,713 Jul-06-2020, 02:34 PM
Last Post: mp3909
  [Django] css file is not applying to the page SheeppOSU 1 3,029 May-09-2020, 06:54 AM
Last Post: menator01
  use Xpath in Python :: libxml2 for a page-to-page skip-setting apollo 2 3,578 Mar-19-2020, 06:13 PM
Last Post: apollo
  Django Two blocks of dynamic content on one page iFunKtion 5 4,338 Jul-04-2019, 02:31 AM
Last Post: noisefloor
  Django: How to automatically substitute a variable in the admin page at Django 1.11? m0ntecr1st0 3 3,245 Jun-30-2019, 12:21 AM
Last Post: scidam
  pull streams from Twitch with a keyword in title maddensplayers 1 2,129 Feb-18-2019, 03:19 AM
Last Post: SheeppOSU
  Sorting getting off, when I switch page Django 1.11 m0ntecr1st0 0 1,957 Feb-12-2019, 06:40 PM
Last Post: m0ntecr1st0

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020