Link a .css to a Html template

68 views
Skip to first unread message

Leó Horváth

unread,
Dec 1, 2019, 8:27:34 PM12/1/19
to Django users
Hi guys, I am experiencing an error while trying to Link a .css file to a Html template of one of my Views. What is the correct way to do it?

אורי

unread,
Dec 1, 2019, 9:33:21 PM12/1/19
to django...@googlegroups.com

On Mon, Dec 2, 2019 at 3:26 AM Leó Horváth <horvath...@gmail.com> wrote:
Hi guys, I am experiencing an error while trying to Link a .css file to a Html template of one of my Views. What is the correct way to do it?

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/b37e10ec-3b9d-4178-8757-1d0277f6cd15%40googlegroups.com.

Leó Horváth

unread,
Dec 2, 2019, 2:16:27 PM12/2/19
to django...@googlegroups.com
hi! i still cant make it work. this is my html snippet and the .css is located at static/pages/frame.css.
when i run the server the browser displays the hard coded html but not the style. console says "GET /static/frame.css HTTP/1.1" 404 1651
<!DOCTYPE html>

{% load static %}

<html>
    <head>
        <meta charset="UTF-8">
        {% block css %}
            <link rel="stylesheet" href="{% static 'frame.css' %}" />
        {% endblock %}

‪‫אורי‬‎ <u...@speedy.net> ezt írta (időpont: 2019. dec. 2., H, 3:33):‬

Kevin Dublin

unread,
Dec 2, 2019, 3:41:45 PM12/2/19
to django...@googlegroups.com
Hi Leo,

Make sure that you point to the exact directory where the CSS file is located. If it's in static/pages/frame.css, then point to {% static "pages/frame.css" %}

Cheers,

Kevin

Leó Horváth

unread,
Dec 2, 2019, 5:09:56 PM12/2/19
to django...@googlegroups.com
hi,
I did what Kevin requested, now console says "GET /pages/ HTTP/1.1" 200 536 and the style still doesn't work. 
Any ideas?
Thanks,
Leó

Suraj Thapa FC

unread,
Dec 2, 2019, 5:55:58 PM12/2/19
to django...@googlegroups.com

Gerardo Palazuelos Guerrero

unread,
Dec 2, 2019, 6:20:54 PM12/2/19
to django...@googlegroups.com
Hi,
You better share your repo, my guess is you are not sharing all details...

On my case I integrated a template with a Django project as a practice ( my repo: https://github.com/gpalazuelosg/django-adminlte ), the important bits:

#1: settings.py has at the end two entries:
STATIC_URL = '/static/'
STATICFILES_DIRS = (os.path.join(BASE_DIR,'static'),)

#2: I have an "static" folder at the same level as manage.py, which has another folder called "base" inside

#3: inside the /static/base folder, I have the following folders containing pertinent files as you might imagine:
css
js
img
plugins

#4: On my layout.html file, I use the following:
{% load static %}
...
<link rel="stylesheet" href="{% static 'base/css/adminlte.min.css' %}">


This is how it looks:



I hopes that helps.

--
Gerardo Palazuelos Guerrero



Integr@te System

unread,
Dec 3, 2019, 1:29:46 AM12/3/19
to django...@googlegroups.com
Hi Leo,

Plz look at err/change log in developer tools to inspect whats up, after you adjust files.



Leó Horváth

unread,
Dec 3, 2019, 2:14:17 PM12/3/19
to django...@googlegroups.com
hi guys, its still not working, one of you asked for my repo so here it is:  https://github.com/leocsi/salesgrade
Any idea what might be wrong? 

Thanks, 
Leó

Aline Balogh

unread,
Dec 4, 2019, 6:28:08 AM12/4/19
to Django users
Hi Léo.

Remove the # from the html class attribute .

<div class="menu_bar">

Leó Horváth

unread,
Dec 4, 2019, 2:42:58 PM12/4/19
to django...@googlegroups.com
Hi Aline, 
THANK YOU VERY MUCH, you solved my 3 day dilemma, and thank you for everyone who tried to help, you guys are awesome!
Thanks a lot,
Leó


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages