The custom font is failing to load on a basic HTML website

I've been exploring different code and examples online in an attempt to incorporate a custom font into my simple HTML website. Just for reference, I'm using Django.

Key files to note:

aurebesh_translator.html

<!DOCTYPE html>
<html>
    <link rel="stylesheet" type="text/css" href="main.css">
    <p>This text should appear in aurebesh</p>
</html>

main.css

@font-face {
    font-family: "aurebesh";
    src: url(aurebesh.ttf);
    font-style: normal;
    font-weight: 100;
}

p {
    font-family: aurebesh;
    font-weight: 100;
}

The file structure looks like this:

| templates
| - ...
| - main.css
| - aurebesh_translator.html
| - fonts
| -- aurebesh.ttf

... where the aurebesh.ttf file is the font file associated with the font I wish to utilize.

Everything seems to be correctly formatted based on my research online for using a custom font. Strangely, if I move these files to my desktop (so that only main.css, aurebesh_translator.html, and fonts/aurebesh.ttf are present) and open aurebesh_translator.html in a browser, the font loads and applies successfully! What's puzzling is that when I integrate these files with the rest of my website's files, the custom font stops working. I've tried opening it in both Chrome and Firefox, but neither browser displays my custom font.

When I try to access the page, this is the error message that displays in my terminal:

[01/Jun/2020 00:08:18] "GET /articles/aurebesh_translator HTTP/1.1" 200 127
Not Found: /articles/main.css
[01/Jun/2020 00:08:18] "GET /articles/main.css HTTP/1.1" 404 4061

How can I resolve this error?

Answer №1

To successfully incorporate static files into your Django project, follow these steps:

  1. Create a folder named "static" and place the following files inside:
  2. main.css
  3. aurebesh.ttf
  4. fonts

Remember that in Django, static files like CSS or images cannot be directly used in HTML. You need to load the static file in HTML and update the file path accordingly. Here's an example:

<!DOCTYPE html>
<html>
{% load static %}
    <link rel="stylesheet" type="text/css" href="{% static 'main.css' %}">
    <p>Make sure this text is displayed in Aurebesh font</p>
</html>

Answer №2

To include CSS or JavaScript static files in Django, make sure to use the static tag within the href attribute. For example,

href = "{% static 'path_of_file' %}"
In this instance, you can use href = "{% static 'main.css' %}" https://i.sstatic.net/i7t4m.png

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

The clickable area for the radio button cursor is too large

As I embark on my journey with HTML and CSS, I have encountered two issues while creating a form: The spacing between the question and answers is too wide. The second picture depicts how I would like it to appear. The cursor:pointer seems to be extending ...

What is the best way to display content next to an image, as well as below the image once it finishes?

Currently, I am working on customizing my blog posts in WordPress. My goal is to have the content of each post displayed next to the post thumbnail, and once the image ends, the content should seamlessly flow underneath it from the left side. I have imple ...

Using ngFor in Angular 2-5 without the need for a div container wrapping

Using ngFor in a div to display an object containing HTML from an array collection. However, I want the object with the HTML node (HTMLElement) to be displayed without being wrapped in a div as specified by the ngFor Directive. Below is my HTML code snipp ...

Guide on verifying a condition within a DRF Serializer and proceeding to the next iteration without processing

In the code snippet below, I have a serializer: class CustomerSerializer(serializers.ModelSerializer): product = serializers.SerializerMethodField() def get_product(self, obj): obj.product = Customer.check_is_product(obj.product_id) ...

Find the line containing the selected text within a JavaScript code

I am working on a contentEditable div where users can enter multi-line text. I need to be able to inspect the line that the user is currently typing in when they press enter. Is there a way to retrieve the context of that specific line (or all lines)? Is ...

Enhancing CSS with Additional Properties

As a web developer, I recently had the opportunity to explore the new LOGIN PAGE preview of GMAIL and was very impressed with the Sign In button's UI. After examining the Page's CSS, I discovered some interesting properties, such as: **backgroun ...

Issue encountered when toggling flip switch in Jquery Mobile

I am trying to create a calculator for my app using Jquery Mobile, but I am facing an issue with the flip toggle switch. Here is my script: <script type="text/javascript"> function dosis() { $peso = $('#peso').get(0).value $dosis = ...

Creating a color gradient for hyperlinked text when hovered over: a tutorial

How can I achieve this effect using CSS only? I want the link color to change from #00C to #000 when hovered over, with a gradient transition taking 1 second. ...

One crucial factor to consider when dealing with dual screen setups is the

Imagine you have the following code snippet : <ul> <li>Menu1 <ul class="submenu"> <li class="firstmenu">submenu-1</li> <li>submenu-2</li> < ...

The Best Practices section of the Chrome lighthouse report has identified an issue with properly defining the charset

I recently noticed an error in my VueJs SPA application when running a Chrome Lighthouse report. The error message indicated that the charset was not properly defined, even though I had added it to my index.html file. Below are screenshots of the issue: ...

Visualizing Data with HTML and CSS Chart Designs

I'm seeking assistance with creating an organization tree in a specific layout. https://i.sstatic.net/z9LRc.jpg I am having trouble replicating the tree structure shown in the image. I need help generating a similar tree structure where multiple le ...

Tips for Successfully Passing Personal Parameters Using Html.BeginForm

I am looking to pass some additional parameters from my MVC Form to the Controller. Can anyone provide guidance on how to accomplish this? Specifically, I want to pass parameters for StateName and CityName with values from the form so that I can retrieve t ...

Switch image upon hover within a sprite

I have a sprite that I utilize for displaying various images. Currently, my aim is to change the sprite image upon hovering using solely CSS. .sprE { background-color: transparent; background-image: url(/i/fW.png); background-repeat: no-repeat; height: 30 ...

The margin and width of a div element with the position set to fixed and display set to table-cell are not rendering correctly

Is there a way to keep my .nav-container position: fixed; without creating a gap between it and the .page-content at certain window widths? When I set the position to fixed, a small white line appears between the red background of the .nav-container and th ...

Rearranging the layout of elements: CSS switches up the text and button,

Having an issue. I created a background image with gradient colors for my web project and clipped it. Within this element, there is text and a button that I want to be centered inside the element - with the text above and the button below. Initially, ever ...

"Troubleshooting: Why isn't my jQuery AJAX POST request successfully sending data to

Here is the jQuery code snippet that I am currently working with: $("#dropbin").droppable( { accept: '#dragme', hoverClass: "drag-enter", drop: function(event) { var noteid = "<?=isset($_POST['noteid']) ? ...

Chrome may clip the gradient radius when setting the focal point outside of the SVG gradient

I just joined this community and I might have some questions that could be considered too basic. Recently, I've been trying to understand SVG and came across something that left me puzzled. Take a look at this: <svg xmlns="http://www.w3.org/20 ...

Tips for displaying or concealing data in table cells in Google Charts

Using a Google charts table to display server exceptions, but the errors are too long for cells. How can I show only an excerpt of error messages in each cell with a + expansion sign for full details in a modal box on click? I have successfully implement ...

I keep running into this issue with Django, where I'm attempting to execute a 304 not modified response. What could be causing this error?

def handle_ajax_request(reqest): #q = request.GET.get('q',None) #fetch all records where var equals q. return ... handle_ajax_request = condition(etag_func=handle_ajax_request)(handle_ajax_request) My intention is to send a 304 statu ...

How can you toggle the visibility of a div based on detecting a specific class while scrolling?

My webpage features a sticky header that gains an extra .header-scrolled class when users scroll down. I am looking to switch the logo displayed in the header once it has been scrolled. Below is a simplified version of my HTML code: <header class=".he ...