N
N
Nevars2014-02-21 22:16:19
Django
Nevars, 2014-02-21 22:16:19

How to include css in django?

Hello! I'm learning django. I'm trying to connect static files to the project (css files), but it doesn't work.
I did everything as in the django documentation, like here How to connect css styles to Django?
Nothing comes out.
Template code:

<!DOCTYPE html>
<html>
    <head>
        <title>Welcome to Inwater</title>
        <link href="{{ STATIC_URL }}welcome.css" rel="stylesheet" type="text/css" media="screen"/>
    </head>
    <body>
        <h1>Hi everyone</h1>
    </body>
</html>

Part of the settings.py file code:
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.6/howto/static-files/

STATICFILES_DIRS = '../static/'

STATIC_URL = '/static/'
STATIC_ROOT = '/static/'

url.spy code:
from django.conf.urls import patterns, include, url
from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('inwaters.views',
    url(r'^$', 'welcome',),
    url('^registration/$', 'registration',),
    url(r'^admin/', include(admin.site.urls)),
)

In css file:
body {
    background-color: green;
}

Answer the question

In order to leave comments, you need to log in

3 answer(s)
H
Huey, 2014-02-21
@huey

No need to rely on django 1.4 there is no longer the same as in 1.6.
It's better to go through this tutorial here, this is an off-book translated by djbook.ru/rel1.6 starting from part 1 and then read the doc, the questions will go away.
If you are too lazy, then in the last part of the tutorial about static files djbook.ru/rel1.6/intro/tutorial06.html Read carefully. If you have any questions about Django, then ask them here djbook.ru/forum/forum/2 .

T
tema_sun, 2014-02-22
@tema_sun

STATIC_ROOT and STATICFILES_DIRS must be an absolute path. Plus, you need to configure the processing of statics. If you are using a dev-server from the djanga kit, then you need to add one line to urls.py (there is one in the docks). If something else, then the web server needs to be configured so that /static/ is not processed by janga.

N
Nevars, 2014-02-22
@Nevars

<!DOCTYPE html>
<html>
    <head>
        <link rel="stylesheet" type="text/css" href="/static/css/welcome.css"/>
        <title>Welcome to project</title>

    </head>
    <body>
        <h1>TEST</h1>
    </body>
</html>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question