django serving static files
In order to serve static files, you need to configure settings.py. In this example, say we are hosting our static files under a folder called 'static' (and app) with a filename called index.html.
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': ['static', 'app'],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
And finally set your "urls.py"
from django.conf.urls import url
from django.views.generic.base import TemplateView
urlpatterns = [
#url(r'^$', views.index, name='index2'),
url(r'^$', TemplateView.as_view(template_name='index.html')),
]
Please note : You should always use default web server to serve static files. The code above is best used for development purposes only.
Please note : You should always use default web server to serve static files. The code above is best used for development purposes only.
Comments