-1

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?

AbtPst
  • 7,778
  • 17
  • 91
  • 172

1 Answers1

2

You should be using the static template tag

{% load static %}
<img src="{% static 'myApp/images/xyz.png' %}">
Sayse
  • 42,633
  • 14
  • 77
  • 146
  • 1
    Also, make sure you have ran `collectstatic`. – Sayse Mar 01 '16 at 14:29
  • i get You're using the staticfiles app without having set the STATIC_ROOT setting to a filesystem path. – AbtPst Mar 01 '16 at 14:30
  • if i do, STATIC_ROOT = '/static/' i get You have requested to collect static files at the destination location as specified in your settings: C:\static This will overwrite existing files! Are you sure you want to do this? – AbtPst Mar 01 '16 at 14:31
  • i tried to set the static root to the absolute path of my static folder. then i rant the collectstatic and got WindowsError: [Error 123] The filename, directory name, or volume label syntax is incorrect: – AbtPst Mar 01 '16 at 14:35