I know there are a few questions like this, but none of them have worked for me. I have django version 1.9.2. The documentation was not of much help wither as i found it quite confusing. Here is my set up
myApp-
static-
myApp-
scripts-
scripts.js
images-
xyz.png
templates-
myApp-
index.html
in my settings.py
i have
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'campaign.apps.CampaignConfig'
]
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'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',
],
},
},
]
STATIC_URL = '/static/'
and my webpage has
<script language="javascript">var STATIC_URL = '/static/';</script>
<script src="{{ STATIC_URL }}myApp/scripts/scripts.js"></script>
and this does not get recognized. neither does this
<img src="{{ STATIC_URL }}myApp/images/xyz.png">
what other changes do i need to make? Is this the correct approach?
You should be using the static
template tag
{% load static %}
<img src="{% static 'myApp/images/xyz.png' %}">
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.