Nginx does not serve Django's CSS files as default

After deploying my Django app on a VPS with Nginx and configuring Nginx to handle the static files, I'm encountering a strange issue. While all the images are rendering properly, the CSS doesn't seem to be working at all...

Here is my Django setting:

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

And this is how I've configured Nginx:

location /static/{
    alias /home/xxx/App/django_app/static_root/;
}

In the HTML template, I have included the following lines:

<link rel="stylesheet" href="{% static 'app1/css/style.css' %}" type="text/css" media="all">

<img src="{% static 'app1/images/page1_img1.jpg' %}" alt="">

I have already executed python manage.py collectstatic, and set Debug = False (everything works fine when Debug is true).

All the images are located in

/home/xxx/App/django_app/static_root/app1/images
, while the css files are under
/home/xxx/App/django_app/static_root/app1/css
.

I can confirm that I am able to access the css file using the URL

https://myserver/static/app1/css/style.css
, and there are no error messages in the Nginx log.

I have tried different browsers, cleared cache, restarted the server and Nginx multiple times but still no luck. I am really running out of ideas... Any suggestions would be greatly appreciated.

Answer №1

The issue was resolved through the inclusion of include /etc/nginx/mime.types; in the nginx configuration file...

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

Arrangement of images in an array

Here's the scenario I'm facing. https://i.stack.imgur.com/FbAfw.jpg So, I have an array of images that I want to use to create a gallery with a specific layout. I've tried using grid and playing around with :nth-child(even) and :nth-child( ...

Create a shiny application that makes text bold in the user interface

Can someone please guide me on how to make specific words bold in a sentence within the UI using HTML tags under the h() function? Your assistance is greatly appreciated. Thank you. library(shiny) ui <- navbarPage( title = 'Benvenuto&apos ...

Storing data using Django and mongoengine

For my Django project, I have decided to utilize both Mysql and MongoDB as two separate databases. Here is how I have defined my settings file: DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', 'NA ...

The space residing above my primary container division

I recently finished creating a basic web app, but I'm encountering an issue with the smallest media query where there is an unwanted top gap. Despite trying multiple methods and researching solutions online, I have not been able to resolve this proble ...

Alert: The function DOMDocument::load() is detecting additional content at the conclusion of the document

Hello, I am facing an issue with appending data to an existing file. Whenever I try to add new data, the existing data gets overwritten. Can someone please help me identify what I am doing wrong? Following the comments, I made changes to the code but now ...

Creating a QR code using base64 in PHP and HTML

My PHP code generates QR codes in WordPress, but some tax roles require the code to be in base64. I need help converting my code to work with Hexadecimal Encoding 64 and utf8. Here's a snippet of my current code: <?php $barcodetype = ...

The cascade of CSS elements arrangement

I have two unique boxes set up like this: <div id="box1"></div> <div id="box2"></div> The second box, box2, has a border and I'm looking to cover the top border with box1. To achieve this, I've applied a negative margin- ...

What could be the reason for the malfunction of my AJAX post request?

I am facing an issue with my AJAX method in Django - it doesn't seem to be working properly. The problem is, I can't pinpoint where the issue lies because there are no errors showing up in the Django debug log, and it returns a 200 status code. ...

Django view function is not being executed

Looking at the view.py, it seems that the show_checkout function is executing successfully until it reaches the line return HttpResponseRedirect('/receipt/'). However, for some reason, the receipt view is not being triggered. None of the print st ...

Shorten a data point in JSON code

I'm currently in the process of developing a stock widget that utilizes JSON to retrieve data from the Yahoo API/YQL console. I am specifically working with values extracted from the key ChangePercentRealtime, however, the values are longer than what ...

What is the best way to horizontally center a child div within its parent container while keeping it fixed at the top?

I am struggling to center a child div horizontally within its parent div while also fixing it to the top of the parent. I have tried various approaches in CSS, but so far I haven't been successful :-( I can either center it or fix it to the top, but w ...

Having difficulty swapping out images on an HTML website template for Internet Explorer

Recently, I obtained an HTML website template that I am currently working on customizing. One of the tasks I have been tackling is replacing some of the existing images with my own. After resizing the new images to match the dimensions of the originals, ...

Could there be a coding issue stopping <div class="rating"> from aligning more centrally along the horizontal axis on the screen?

Just wondering, could there be something in my code that's preventing <div class="rating"> from moving closer to the center? And is there a way to make it move closer horizontally? (On a side note, CSS layout and positioning still puzz ...

Setting up the foundation for a Bootstrap footer: A step-by-step guide

I've been struggling to implement the HTML5 structure within Bootstrap 4 grid system to match the design shown in the attached images. The layout should resemble the top image when viewed on a phone, phablet, or tablet in portrait mode, and the bottom ...

Leveraging the power of Bootstrap and JavaScript to implement a custom Toast feature

I am utilizing Bootstrap 4 to design Toasts, and I am presently developing a JavaScript function to generate a toast. My attempt to create elements within the JS file did not properly style it. index.html <!doctype html> <html lang="en"> ...

Utilizing JavaScript to trigger an alert message upon selecting various options and blocking the onclick event

Setting up a simpleCart(js) with selectable options presents a challenge. The task at hand is to display an alert if not all drop-downs meet specific requirements and to prevent the "Add to cart" button from adding items to the cart when these conditions a ...

adjusting the background with repeat-y pattern placement

I'm having an issue with setting a background image as a wrapper for the main content of my page. Currently, I've set the background image like this: #background { background: url("../image/bg.png") repeat-y 133px 50px; color: #000000; ...

What steps do I need to take in order to include REMOVE and EDIT buttons in my table?

In the index.html file, there is a teacher table that is only displayed after clicking on the button Teachers: <div class="container"> <table class="teacherTable" border="1" width="100%" cellpadding=&qu ...

Search button in Bootstrap navbar misplaced

Following Dennis Ivy's tutorial on an ecommerce site, I attempted to implement the navbar from here (the first example). However, after copying and pasting the code and ensuring proper indentation, the search field and button appear misplaced. A snipp ...

Accessing CSV data stored externally using JavaScript

Hi there, I am struggling to load external CSV data into a script due to what I believe is the browser's same origin policy restriction. I came across some information about using cross-document messaging as a workaround, but I have no idea how to go ...