Customizing Django Templates with Jinja for Stunning Background Images

I am facing an issue with displaying my background image on my website. I have added the background image in my style.css file and linked it in .

I placed {% load staticfiles %} above the style tag, but I believe this may be incorrect.

I have verified my settings and the STATIC_URL is set as follows: STATIC_URL = '/static/'

Below is my CSS code

style.css

body {
    background:slategray url("/personal/static/personal/images/background.gif")no-repeat right bottom;
}

Here is my HTML code

<!DOCTYPE html>
<html lang="en">
  <head>
      <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <title>Mr. Hart</title>


      <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css" integrity="sha384-/Y6pD6FV/Vv2HJnA6t+vslU6fwYXjCFtcEpHbNJ0lyAFsXTsjBbfaDjzALeQsN6M" crossorigin="anonymous">

      <div class="row">
        <div class="col-md-8">
            <a href='/' style="display: inline-block; text-decoration-color: #1a8002;">Home</a>
            <a href='/blog/' style="display: inline-block; text-decoration-color: green;"> Blog </a>
            <a href='/Aboutme/' style="display: inline-block; text-decoration-color: green;"> About Me </a>
            <a href='/stocks/' style="display: inline-block; text-decoration-color: green;"> My stock Tips </a>
            <a href='/crypto/' style="display: inline-block; text-decoration-color: green;"> Crypto </a>
        </div>
        <div class="col-md-4">"This is where my contacts stack,github, stocktwits, twitter, all picture links "</div>
      </div>

      {% load staticfiles %}
      <style type="text/css">
        html,
        body {
          background: url("{% static "/personal/style.css" %}") no-repeat center center fixed;
          -webkit-background-size: cover;
            -moz-background-size: cover;
            -o-background-size: cover;
            background-size: cover;
        }
    </style>
  </head>

Answer №1

It seems that the issue lies in not being able to locate the static file due to the presence of a slash.

Let's test this theory by using a static file that we know exists:

$ ./manage.py findstatic admin/js/vendor/jquery/jquery.js
Found 'admin/js/vendor/jquery/jquery.js' here:
  /home/jpic/.local/lib/python3.6/site-packages/django/contrib/admin/static/admin/js/vendor/jquery/jquery.js

Now, let's try the same command with a prefixed slash:

$ ./manage.py findstatic /admin/js/vendor/jquery/jquery.js
Traceback (most recent call last):
  File "./manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/home/jpic/.local/lib/python3.6/site-packages/django/core/management/__init__.py", line 353, in execute_from_command_line
    utility.execute()
  ...
  django.core.exceptions.SuspiciousFileOperation: The joined path (/admin/js/vendor/jquery/jquery.js) is located outside of the base path component (/home/jpic/src/django-autocomplete-light/test_project/linked_data/static)

For more information on handling static files in Django, refer to the official documentation and additional blog articles:

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

Encountering an error with custom views due to lack of matching query

After encountering some form manipulations, I found myself in need of writing custom views. Following the example in the cookbook, my view now looks like this: if request.POST: if includeHelper.check_valid(): process = includeHelper.save() ...

The proper method for setting up and tearing down login and logout functionalities in Django

For testing a polling application I developed with django, it is necessary for users to be logged in before they can vote or view results. I wanted to create a test suite where the setup involved creating a test user, logging them in, and tearing down by l ...

Having difficulty passing an array list from JavaScript to a Django View

I am struggling with handling an array called tableData in Python. Despite using print(pieFact), I am not seeing any output on my terminal. Additionally, when I include 'test': tableData within var data = {'test': '2', csrfmid ...

Replacing the previous observation

My events app features an all-events component that showcases all the events created. Upon loading the all-events component, the events are fetched from the database. Below is a snippet of the relevant code from the Typescript file of the all-events compo ...

Unexpected character appearing in Android 2.3, whether using the li or ul tag

Having an issue with my social icons on the top of my website displaying unwanted symbols in Android 2.3. Can't figure out the cause even after ruling out <a> tags and associated CSS. Any thoughts on what the problem might be? I've remove ...

Disabling or Concealing the Timer in angularJS: A Step-by-Step Guide

In my project, I have integrated a Timer and Countdown Timer that counts down from 59 seconds to 0 seconds in reverse order using AngularJS. However, I am facing two issues that need to be resolved. Can anyone provide assistance? Issue 1: The problem lies ...

New feature: Material UI Chip Input with floating input label

I installed material-ui-chip-input to implement tags in an input field. I wanted a label alongside it, so I utilized the default Material UI label for consistency with other inputs. However, the input doesn't shrink as expected when clicked on by the ...

Is it advisable to utilize media queries and transform: translateY(-%) to position content above the mobile keyboard?

I've been struggling for nearly a whole day and could really use some assistance. I'm having trouble understanding how chat web apps manage to work around this particular issue. There have been numerous forum posts discussing the problem: I am tr ...

Troubles encountered with adapting apexcharts size within a react environment

As a novice front-end coder transitioning from a data analyst background, I am currently facing an issue with integrating an ApexChart visual into a flexbox element. The visual appears fine at a resolution of 2560x1440 pixels. However, upon further resizin ...

In the realm where jQuery meets Django, a mysterious pair of brackets mysteriously appear in my JSON data, causing form validation to

In my Django model, there is a ManyToMany field named images, and I have created a simple ModelForm for this model. I am attempting to send data using jQuery along with a basic UpdateView. The field in the model images = models.ManyToManyField( RawI ...

What is the best way to eliminate the dotted border from clickable images?

The client has expressed their dislike for the dotted border, but I believe it is important to keep it for accessibility reasons. However, I suppose I will have to remove it since the client requested it. How should I proceed? ...

Obtain the computed style by utilizing setTimeout for effective functionality

I want to retrieve the calculated style (background-color) of a span element. Here's my HTML code, consisting of two label elements, each containing an input and a span: <label> <input type="radio" name="numbers" value="01" checked/> ...

Looking to create a subtle border with rounded edges

https://i.sstatic.net/oFS4t.png I'm currently working on creating a smooth, fading green line using an array of points in my code. for(var i = this.trail.length - 1; i > -1 + 1; i--) { var time = this.trail[i][0]; var pos = this.trail[i][ ...

Transfer text from one form to a text field on a different website

I've created a form that allows users to input numbers in a field and then directs the page to a specific URL. Here's the code snippet: <html> <head> <meta charset="utf-8"> <title>Tracking</title> </head& ...

Targeting an HTML form to the top frame

Currently, I have a homepage set up with two frames. (Yes, I am aware it's a frame and not an iFrame, but unfortunately, I cannot make any changes to it at this point, so I am in need of a solution for my question.) <frameset rows="130pt,*" frameb ...

Limiting the options available in dropdown menus

In my HTML code, I have two drop-down lists that look like this: <select name="from" id="abs-from-1"> <option value="1">One</option> <option value="2">Two</option> <option value="3">Three</option> ...

FormModel provides the official description for uploading files, yet the issue persists where form.is_valid always evaluates to false

I'm currently working on implementing FormModel to manage file uploads. However, I've encountered an issue where form.is_valid() always returns false without displaying any errors. Below is a code snippet from my models.py, forms.py, views.py, an ...

Modifying CSS content attribute in real-time

A colleague of mine has rented a webshop from a company. They have the option to select different templates and are also able to customize the CSS and add Javascript snippets. They reached out to me for help with making some modifications, but there's ...

"What is the best way to use JavaScript to dynamically modify the hover color of a button

I am looking to customize the hover color of all buttons on my website to align with the overall theme. The challenge is that I need the hover color to vary based on the page it originates from. I have successfully identified the referring page, but I am s ...

Adjust the alignment of text within the <select> tag to the right in Safari browser

Is there a way to align text right in a select option tag? <select style="direction:rtl;text-align:right"> <option value="" selected="">همه</option> <option value="1">راهبر سيستم</option> <option v ...