Answer the question
In order to leave comments, you need to log in
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>
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.6/howto/static-files/
STATICFILES_DIRS = '../static/'
STATIC_URL = '/static/'
STATIC_ROOT = '/static/'
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)),
)
body {
background-color: green;
}
Answer the question
In order to leave comments, you need to log in
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 .
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.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question