What could be causing the partial failure of my CSS stylesheet in my Django application? Could it be related to retrieving data from the database?

After following various tutorials, including one on LinkedIn, I believe my Django settings are correct. However, I am facing an issue with the CSS stylesheet in my app. The styling works perfectly everywhere except for the section where I retrieve data from PostgreSQL. Strangely, when I remove the PostgreSQL code, the CSS starts working again in that area. I have also made sure to include {% load static %} at the top of my HTML file.

Below is the HTML snippet:

Code Snippet when it works:

<div class="skills">
    <h2>Stories!!!!</h2>
    <div class="skill-row">
      <img class="princess-img" src="https://media.giphy.com/media/ZETg64fW7xb0gr4NEz/giphy.gif" alt="princess-img">
      <h3><a href="Repunzel.html">Repunzel!!</a></h3>
      <p>Lets see how Repunzel manages to escape the tower, have an adventure and finds out the truth!!.</p>
    </div>
    <div class="skill-row">
      <img class="alladin-img" src="https://media.giphy.com/media/OoOvAC7vASedB6EhpS/giphy.gif" alt="alladin-img">
      <h3><a href="Allading.html">Alladin!!</a></h3>
      <p>Let's see if Kitty, Jasmine and Alladin manage with Genies' help to outsmart the baddies!!.</p>
    </div>
  </div>

/When it doesn't work/

<div class="skills">
    <h2>Stories!!!!</h2>

    {% for drawing in drawings.all %}

    <div class="skill-row">
      <img class="{{drawing.classname}}" src="{{drawing.source}}" alt="{{drawing.classname}}">
      <h3><a href="{% url 'detail' drawing.id %}">Repunzel!!</a></h3>
      <p>{{ drawing.summary }}</p>
    </div>
    {% endfor %}
  </div>

The issue seems to be related to the CSS styling not working within the Django for loop when retrieving data from PostgreSQL using the drawing object defined in my model. Although I do connect to the database and retrieve the data, the specific part styled by CSS is affected.

Below are the views and models code:

#views.py
from django.shortcuts import render,get_object_or_404
from .models import Drawing

def drawingshome(request):
drawings = Drawing.objects
return render(request, 'drawings/drawingshome.html',{'drawings':drawings})

#models.py
from django.db import models

class Drawing(models.Model):
 image = models.ImageField(upload_to='images/')
 summary = models.CharField(max_length=200)
 classname = models.CharField(max_length=200, default='0000000')
 source = models.CharField(max_length=200, default='0000000')
 altname = models.CharField(max_length=200, default='0000000')


def __str__(self):
    return self.summary

Thank you for taking the time to assist me with this issue!

Answer №1

Create a new variable.

designs = 'mysql_db_data' 

Attempt this:

{% for design in designs %}

Note: I have excluded .all and 'mysql_db_data' represents your database query instance.

I have used this method in various projects and it has been successful.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the best way to ensure that the Bootstrap navbar remains collapsed at all times, regardless of the size of the

Is there a way to keep my Bootstrap navbar constantly collapsed regardless of the screen size? I'm currently using Bootstrap, and I've noticed that when the screen is larger, the navbar expands automatically. What can I do to ensure that the navb ...

What is a method to resize an SVG path to a specific pixel size without altering any of the SVG attributes?

Is it possible to adjust the size of a <path> to fit a specific px dimension by simply altering the attributes of the path itself? Within an SVG, I have a carrot symbol represented by a <path>. <svg height="600" width="400"> <p ...

Comparison between Bootstrap 4 and Firefox Preload Error

Hello fellow front end developers who are experiencing an issue with CSS preload in Firefox versions above 74.0. I have encountered a problem with the following code snippet: <link rel='preload' as='style' onload="this.onload=null; ...

An issue has occurred due to an illegal mix of collations (greek_general_ci,IMPLICIT) and (utf8_general_ci,COERCIBLE) when performing the operation 'like'

Although this topic has been extensively covered, my issue presents a slightly different challenge. I have set the default charset to utf8 in both the connection made to mysqldb in my Python code and my HTML files. conn = pymysql.connect(host='my ...

Create a unique margin using CSS only that will appear at the bottom of a flex-row container that scrolls

I'm trying to create a horizontal scroller with margins between each item and consistent margins at both ends. However, I'm noticing that the margin at the end of the container seems to be disappearing somehow. Is there a way to maintain the mar ...

When the draggable item is released near the drop zone, allow drag and drop to combine

In my latest project, I created a fun game that involves matching different shapes. The goal is to drag the correct figure next to its corresponding shadow figure for a perfect match. Currently, if you partially overlap the square with its shadow, the game ...

Deciphering HTML encoding for text fields

As I transition from the Microsoft stack, specifically WPF, to HTML5, I apologize for any beginner-level questions. Today's topic is HTML encoding and decoding. Imagine an HTML5 application making AJAX calls to a C# backend using HTTP. The server al ...

"Is it possible to keep an eye on two different events and take action once they both

I have a menu with different submenus for each list item, all utilizing the same background tag. Currently, when one submenu is open and I hover over another list item, the previous submenus hide and the new one opens. What I want is for the content to cha ...

`Can Beautiful Soup extract data (text) from elements that share the same class identifier?`

Currently working on a personal project focused on web scraping, using beautiful soup to extract data from a website. Encountered an issue where data with the same class but different attributes is present. For instance: <div class="pi--secondary-price ...

"Problem with binding a dropdownlist to an object causing the selected object not to return

I have successfully bound an object to a dropdownlist using Knockout 2.2.1. The binding correctly displays the items in the list, but I am facing difficulties retrieving the selected OBJECT. To illustrate this issue, I have created a JSFiddle: http://jsfid ...

Display a table image in a new location on the HTML page through dynamic rendering

I am working on a task where I need to retrieve the content of the 'Photo' column for a specific row in a table and display the corresponding image on an HTML page. The 'image' column contains paths to jpg images. For instance, if we s ...

Creating dynamic and fluid motion with Bezier curves on canvas

I am currently working on creating a line that spans across the canvas from left to right. In these early stages of development, I am using a step-by-step animation approach with the following function: timer = window.setInterval(draw_line, 30); Here is ...

Utilizing Angular Forms for dynamic string validation with the *ngIf directive

I have a challenge where I need to hide forms in a list if they are empty. These forms contain string values. I attempted to use *ngIf but unfortunately, it did not work as expected and empty fields are still visible in the list. How can I address this iss ...

Incorporating .txt files into a static webpage using only HTML and JavaScript

Exploring the realm of web page creation for the first time has left me in need of some guidance. I have successfully added an upload feature for text files on my web page, but I am struggling to embed a text file directly into the page source. With Java s ...

Encountering the error message "Cannot GET /" in a NodeJS Express

I've been experimenting with various approaches to resolve this issue, ranging from app.use(express.static(__dirname + "public")) to res.render. It seems to function correctly in my terminal environment but fails when I try to access it locally. Can a ...

Fixing the filter button: A step-by-step guide

I'm new to html and spring boot, and I'm currently working on filtering and searching for books in a list based on the author, description, etc. However, it seems that my button isn't functioning properly. Can someone please assist me with t ...

Navigating through tabs in a Meteor application: How to maintain the active tab when using the back button

I am working on a multi-page meteor application where each page includes a navigation template. To switch between pages, I am using iron-router. The user's current page is indicated by setting the appropriate navigation link's class to 'ac ...

display data labels within the chart - utilizing the power of angular.js in conjunction with chart.js

My goal is to display the chart's information without requiring the user to hover over any part of the chart. I am utilizing Chart.js with Angular.js I have the same question as this one posted here: question here! html code: <div class="wrapper ...

Error encountered when transitioning to TypeScript: Unable to resolve '@/styles/globals.css'

While experimenting with the boilerplate template, I encountered an unusual issue when attempting to use TypeScript with the default NextJS configuration. The problem arose when changing the file extension from .js to .tsx / .tsx. Various versions of NextJ ...

Deleting sections of a string using JavaScript

I've encountered a rather unique issue where I need to address a bug on a website. The problem is that when a string is generated dynamically, it automatically adds 5 spaces before and after the string. Ideally, this should be fixed in the backend cod ...