0

I have a Django app that uses both JavaScript Files + CSS.

While the css files perfectly loads, all of the the Java Script don't.

CSS file Location:

 C:\Users\user\Desktop\Django project\general\adray\static\adray\assets

JavaScript files location (Yes i checked, java script files are really there):

 C:\Users\user\Desktop\Django project\general\adray\static\adray\js

Here is base.html load stuff:

{% load staticfiles %}

<link rel="stylesheet" type="text/css" href="{% static 'adray/assets/custom.css' %}" />
<link rel="stylesheet" type="text/css" href="{% static 'adray/assets/bootstrap.css' %}" />
<link rel="stylesheet" type="text/css" href="{% static 'adray/assets/font-awesome.css' %}" />

  <script type="text/javascript" src=" {% static 'static/adray/js/jquery-1.10.2.js' %}"></script>
 <script type="text/javascript" src=" {% static 'adray/js/bootstrap.min.js' %}"></script>
  <script type="text/javascript" src=" {% static 'adray/morris/raphael-2.1.0.min.js' %}"></script>
   <script type="text/javascript" src=" {% static 'adray/js/custom.js' %}"></script>
   <script type="text/javascript" src=" {% static 'adray/js/jquery.metisMenu.js' %}"></script>



<!DOCTYPE html> ......

And Server Log (all JavaScript Get requests return 404):

    C:\Users\user\Desktop\Django project\general>python manage.py r
unserver
Performing system checks...

System check identified no issues (0 silenced).
August 13, 2015 - 14:55:26
Django version 1.8.2, using settings 'general.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
[13/Aug/2015 15:04:26]"GET / HTTP/1.1" 200 10215
[13/Aug/2015 15:04:26]"GET /%7B%20%%20static%20'adray/js/bootstrap.min.js'%20%%2
0%7D HTTP/1.1" 404 2706
[13/Aug/2015 15:04:26]"GET /%7B%20%%20static%20'adray/js/jquery-1.10.2.js'%20%%2
0%7D HTTP/1.1" 404 2706
[13/Aug/2015 15:04:26]"GET /static/adray/assets/custom.css HTTP/1.1" 304 0
[13/Aug/2015 15:04:26]"GET /%7B%20%%20static%20'adray/morris/raphael-2.1.0.min.j
s'%20%%20%7D HTTP/1.1" 404 2730
[13/Aug/2015 15:04:26]"GET /static/adray/assets/bootstrap.css HTTP/1.1" 304 0
[13/Aug/2015 15:04:26]"GET /static/adray/assets/font-awesome.css HTTP/1.1" 304 0

[13/Aug/2015 15:04:26]"GET /%7B%20%%20static%20'adray/js/custom.js'%20%%20%7D HT
TP/1.1" 404 2685

Settings.py:

import os

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))



SECRET_KEY = ***********************


DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'adray',
)

MIDDLEWARE_CLASSES = (
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
    'django.middleware.security.SecurityMiddleware',
)

ROOT_URLCONF = 'general.urls'

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',
            ],
        },
    },
]

WSGI_APPLICATION = 'general.wsgi.application'


# Database
# https://docs.djangoproject.com/en/1.8/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}

TEMPLATE_DIRS = (
    'C:/Users/user/Desktop/Django project/general/adray/Templates',
)
# Internationalization
# https://docs.djangoproject.com/en/1.8/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.8/howto/static-files/



STATIC_URL = '/static/'

STATIC_ROOT = "C:/Users/user/Desktop/Django project/general/adray/static"

FIXTURE_DIRS = (
   'C:/Users/user/Desktop/Django project/general/path/to/adray/fixtures/',
)

i also ran:

C:\Users\user\Desktop\Django project\general>python manage.py collectstatic

Any idea on whats going on? Thanks in advance!

4
  • have u done python manage.py collectstatic ? Commented Aug 13, 2015 at 11:50
  • Do i need to do that every time i load a new javascript scr? Commented Aug 13, 2015 at 11:51
  • Yes, On every change on javascript files you should do collectstatic Commented Aug 13, 2015 at 13:22
  • Thanks, did that, still not working :) , ill edit settings.py to add static_root Commented Aug 16, 2015 at 5:29

1 Answer 1

3

Your template tags are not recognized properly because they contain spaces:

{ % static 'adray/js/jquery.metisMenu.js' % }

should be:

{% static 'adray/js/jquery.metisMenu.js' %}
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks, i removed the spaces, still not working, ill edit the question
Did you save your template base.html after removing the spaces?
thanks, your answer did the job! i saved the wrong base.html, so it took me time to find out :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.