Pergunta

I have tried linking a stylesheet to my template in django and it doesnt do anything:

the template(called base.html)

<!DOCTYPE html>
<html>

<head>
<title></title>
<link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}base.css">
</head>
<body>
<h1>Welcome to {{ page }}</h1>
</body>
</html>

This is the settings about the static files:

STATIC_URL = '/static/'
STATICFILES_DIRS = ('C:/Users/GAL/PycharmProjects/sqvatPreAlpha/static/',)

The way my project is built:

https://i.stack.imgur.com/Ldndl.png

What should I do to make it work?

Foi útil?

Solução 2

You have to add {% load staticfiles %} at the beginning of base.html Also, it seems you need to add .cssto your css file.

Outras dicas

You haven't mentioned if this is a dev or production box. If the latter, make sure you run:

python manage.py collectstatic

This will collect all your static files that you have in the Django project root, and copy them to the STATIC_URL directory. If you are still running into problems after trying this, you most likely have something incorrectly defined in your settings file.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top