How to set a custom background image for the Django admin panel

I am struggling to display a background image in the Django admin site. Despite researching multiple solutions, none of them seem to work for me. All I want is for the background to be visible behind the admin site. I have a file named base_site.html.

{% extends "admin/base_site.html" %}

{% load static %}

{% block extrastyle %}

{{ block.super }}

<link rel="stylesheet" type="text/css" href="{% static "css/admin-extra.css" %}" />
{%endblock%}

The admin-extra.css file looks like this:

  head.bg {
  /* The image used */
  background-image: url('{{ STATIC_URL }} background.png') ;

  /* Full height */
  height: 100%;
  /* Center and scale the image nicely */
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
  }

Although the extra-admin.css file is being loaded as confirmed by the Firefox inspector, the image does not appear on the background. It seems like something is there briefly, but it gets covered by the normal admin site with a white background.

Answer №1

After thorough investigation, I have successfully pinpointed the solution. The key lies within base_site.html.

{% load static %}    
{% block extrastyle %}     
{{ block.super }}    
<link rel="stylesheet" type="text/css" href="{% static 'css/admin_extra.css' %}"    />
{%endblock%}

Contained within admin-extra.css, the following styling rules apply:

body {
  /* The image used */
  background-image: url('background.png') !important;
  /* Full height */
  height: 100%;
  /* Center and scale the image nicely */
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
}

Also, within settings.py lies the necessary configurations:

 STATICFILES_DIRS = (
os.path.join(BASE_DIR, "E6000_stitch_techniques", "static"),
)     
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')

It is crucial to monitor the django console for any 404 errors related to serving static files.

Answer №2

To include a new folder in your static directory, follow these steps:

/static/admin/css

Next, within this new directory, copy the admin's base.css file from your site_packages folder.

base.css

Experiment with customizing the base.css file by adjusting the body's background-image. Additionally, consider removing the background: #fff; property.

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

Customize your website with eye-catching full width colored blocks using Bootstrap 3

I am in need of colorful full-width blocks to differentiate the sections on my website. Currently, I am constructing my website with Bootstrap 3 within a standard container. However, I would like certain sections to be vibrant blocks that span across the ...

Tips for resizing a larger image to display only a specific portion in CSS (and incorporating JS if needed)

I need to resize an image that measures 1024x1024 and is segmented into 4 quadrants: My goal is to reduce the size of this image so that quadrant 2 is 256x256 while masking out or hiding the remaining 3 quadrants, displaying only the desired section on th ...

Prevent users from clicking by using a CSS class in HTML and JavaScript

,hey there buddy 1° Can you help me figure out how to prevent click behavior using the CSS class? 2° I'm unable to add an ID to the HTML element, so I need to use the Class to achieve this. 3° None of my attempts have been successful so far. El ...

Custom Sizing for Bootstrap Modals

I need assistance with creating a dynamic bootstrap modal that adjusts its width based on the content and includes a vertical scrollbar when needed. Although the vertical scrollbar is functioning correctly, the horizontal width appears to be static. C ...

Creating Dynamic Web Design: Horizontal Scrolling Window and Adaptive HTML Content

After spending countless hours researching online, I am still unable to find a solution for responsive web design that maintains the aspect ratio of both the window and HTML body. Here are examples of what I'm looking for: original view, stretched le ...

Floating boxes with a stationary top alignment

My HTML "toolbar" has multiple widgets displayed in a horizontal layout. Each widget is represented by a div element in the source code: <div id="widget1" /> <div id="widget2" /> <div id="widget3" /> To position these divs, I use float: ...

The jQuery function for $(window).scroll is not functioning as expected

My challenge is getting the scroll to reveal my scrollTop value I've been working with this code: $(document).ready(function(){ console.log('Hello!'); $(window).scroll(function(){ console.log('Scrolling...'); var wScroll = ...

Center the element vertically if its height is less than the container's height, but let its height become 100% if the container's height is

I am trying to achieve a layout where an element (.figure) is centered horizontally when it is shorter than its container (.timeline-content), but matches the height of its container when longer. The height of the container changes based on its parent. T ...

Customize the appearance and text in the navigation bar

Currently, I am in the process of creating my own personal website template. However, I have encountered an issue with styling the image and text within the navbar. I am looking to adjust the aspect ratio of the image in order to center it within the n ...

Discover the most effective method of working with cached values in Django using Redis

Exploring the depths of Redis cache operations within Django has led me to ponder the efficiency of utilizing Redis methods directly. While Redis offers a variety of powerful operations, the native cache module in Django falls short in supporting them. I ...

Step by step guide on creating a CSS triangle shape in front of a span element

Can you help me troubleshoot why my css triangle isn't displaying before my span? I've tried everything but it just won't show up. .triangle:before { width: 0; height: 0; border-top: 3px solid transparent; border-right: 6px solid ...

Updating the background of the <html> tag using jQuery

Is there a way to modify this CSS using jQuery? html { background: yellow; } Attempting the following code does not yield the desired results: $('html').css('background','red'); ...

I'm trying to set it up so that an image pops up when I hover over text. I've tried incorporating a few different JavaScripts, but I still can

I'm struggling to display an image on my website. I have the necessary code parts, but it's not working as expected. function showImage() { $('.img').addClass('display'); } function hideImage() { $('.img'). ...

Issue with alignment of divs causing them to stack in a strange manner instead of floating left and

Check it out in action right here: All I want is for the .news div boxes to gracefully float left and right using the handy cycle helper in Rails. However, the current output isn't quite what I had in mind: This is how I envision the layout should l ...

Adding the children of JSON objects to every individual div element

How can I add each day's players [day-1, day-2, day-3, day-3] wrapped in a <span> into the .card-body section as required? The goal is to load only four card-body. var vehicles = { "day-1": { "player-1-1": "Ford", "player-1-2": "BMW ...

A guide on updating the appearance of a list of comma-separated tags using HTML, CSS, and jQuery

Is there a way to replicate the functionality of the tag section on this website for creating question entries? How can this be achieved? ...

Is there a workaround for lack of border radius support in IE8 when css3PIE is not functioning

I've come across numerous versions of this question, but none have been successful for me. I'm attempting to achieve rounded corners in IE8 similar to what I see in Firefox and Chrome. Below is my CSS code after integrating css3PIE: border-top- ...

React Native: Enhance the background with a vibrant stripe of color

I am trying to incorporate a strip of grey in the middle of my white background, but I am encountering an issue where I am unable to input any text inside it. Below is the code snippet I am working with: container: { flex: 1, justifyContent: "cent ...

Align Image According to Dimensions of the Browser

I'm looking for a way to dynamically position an image based on the width and height of the browser within an HTML file. I know that adjusting an image's width/height is possible through code like this: <script> ...

Is there a way to create an effect where the color of a floating action button changes when you hover over it, similar to a filter?

I'm new to using the <Fab /> element and I'm struggling to figure out how to implement a hover effect that will change the button's color. Here's what I have so far: JavaScript: <Fab variant="extended" className=&quo ...