0

I want to call a HttpResponse from a view in my main.js file, but I'm getting this error in the console //localhost:8000/%7B%%20url%20'join_dpt'%20%%7D 404 (Not Found), everything was fine when I had all in a same index.html file but now I don't want to have the scrips in the index.html so I moved it to a main.js file.

This is how I'm calling the HttpResponse (I was doing the same in the index.html file and it was fine)

d3.json("{% url 'join_dpt' %}")

this is how my folders order:

-- django
  -- env
  -- app
  -- project
    -- urls.py
  -- static
    -- css
    -- js
      -- main.js
  -- templates
    -- index.html

and I have this in my settings.py

STATIC_URL = '/static/'

#new
STATICFILES_DIRS =(
    os.path.join(BASE_DIR,'static'), 
)

any ideas on how can I solve this?

1 Answer 1

1

You can't put django template variables into .js files. The script must be inline in the HTML template file.

Sign up to request clarification or add additional context in comments.

Comments

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.