简体   繁体   中英

Django, serving static files with default settings

I'm writing an app using the Django Python web framework. I added my apps to the INSTALLED_APPS in settings.py and my templates are served without problems. But, concerning the static files, i have a little problem with them. I wanted to use the default parameters in STATICFILES_FINDER :

STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
)

When i want to include a css file for example, in my template i just do (supposing '/' will be my static/applicationName in my application folder) :

<link rel='stylesheet' href="/css/style.css">

Am i doing it wrong, and if so, what's the good way to deal with static files ?

UPDATE : My base.html template :

{% load staticfiles %}
<!doctype html>
<html>
    <head>
        {% block head %}
            <meta charset='utf-8'>       
            <title> {% block title %} {% endblock %} - Find Something </title>
            <link rel='stylesheet' href="{% static  'css/style.css' %}">            
        {% endblock head %}        
    </head>
    <body>

    </body>
</html>

And my inheriting template is :

{% extends "frontend/base.html" %}

{% block title %} {{ title }} {% endblock %}
{% block head %}
{{ super() }}
{% endblock %}
 {% static %}
 <link rel='stylesheet' href="{% static 'css/style.css' %}">

 {% block head %}
     {{block.super}}
 {% endblock %}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM