0

I have a problem with jQuery in my project as I can't successfully call any js function. I have added the jquery library to home.html

<script type="text/javascript" src="{% static '/js/jquery-1.11.3.min.js' %} ">
    </script> 

and I try to call something like:

{% extends "posts/home.html" %}


{% block content %}
<select onchange="dzialaj()">
    {% for author in users %}
        <option value={{author.id}}>{{author.username}}</option>
    {% endfor %}
</select>
<div id='posty'>
</div>

{% endblock %}

but calling even a simple alert() doesn't give any result.

my settings static conf:

    STATIC_URL = '/static/'


CRISPY_TEMPLATE_PACK = 'bootstrap3'



STATIC_ROOT = os.path.join(os.path.dirname(BASE_DIR), "static_env","static_root")

STATICFILES_DIRS = (
    os.path.join(BASE_DIR, "static_pro", "my_static"),
    #'/var/www/static/',
)

MEDIA_URL = '/media/'

MEDIA_ROOT = os.path.join(os.path.dirname(BASE_DIR), "static_env","media_root")

i have loaded static files in my base template too

update: I found that this problem can be a bug in python 2.7 Does someone know how to fix it?

3
  • Do you get any error in your browser's console? Commented Nov 30, 2015 at 12:22
  • coud you add structure of your app, please? precisely the static folder structure Commented Nov 30, 2015 at 12:29
  • No i don't get any errors. Commented Nov 30, 2015 at 19:19

1 Answer 1

1

Check staticfile_dirs in your settings:

STATIC_URL = '/static/'
STATICFILES_DIRS = (
    os.path.join(BASE_DIR, 'static'),
)

Your template:

{% load staticfiles %}

<script type="text/javascript" src="{% static 'js/jquery-1.11.3.min.js' %} ">
</script> 
Sign up to request clarification or add additional context in comments.

5 Comments

I have load static files in my base template and i have configured static files too.
But on your console appears js being called with status 200?
I'm not sure what do u mean but when start load my page on chrome in console i have somethin like this /posts/HTTP/1.1 200 4894 /js/jquery-1.11.3.min.js HTTP/1.1 404 2079
I think your problem is in your static configuration On your console your js should appear: /static/js/jquery-1.11.3.min.js HTTP/1.1 404... Try calling this file by url: localhost:8000/static/js/jquery-1.11.3.min.js
Of course i get 404 error. But what is interesting when i try to get to other static files, images for example there's no problem with that.

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.