38

In a Django app, where should I put my javascript/jquery scripts?

irl_irl
  • 3,785
  • 9
  • 49
  • 60

2 Answers2

30

In with your other static media. See here for more info:

http://docs.djangoproject.com/en/dev/howto/static-files/

Paul McMillan
  • 19,693
  • 9
  • 57
  • 71
  • Thanks. How would I go about using that then? Trying to follow http://blog.dpeepul.com/tag/django-voting/ - Step 4. If I put this code in my media folder, how would I include it? – irl_irl Oct 07 '09 at 17:33
  • Make sure you're serving it properly, according to the link, and then access it at yoururl/yourmedia/, or whatever you've configured it to, perhaps localhost:8000/media/. – Paul McMillan Oct 08 '09 at 08:56
  • 2
    [This question](http://stackoverflow.com/questions/2237418/serving-static-media-during-django-development-why-not-media-root) provides more information – Casebash Jun 14 '10 at 02:04
2

You have defined paths for media and static into the settings.py:

import os.path
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
STATIC_URL = '/static/'
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.abspath(os.path.join(BASE_DIR, '..', 'media'))
STATIC_ROOT = os.path.abspath(os.path.join(BASE_DIR, '..', 'static'))
  • Used BASE_DIR to calculate the path to the settings.py file
  • Used BASE_DIR to generate the MEDIA_ROOT and STATIC_ROOT paths to the previous path of settings

Following that structure the path structure should be:

-yourApp
----manage.py
----media
----static
----yourApp
--------settings.py
--------models.py

Django: How to manage static files

AlvaroAV
  • 10,335
  • 12
  • 60
  • 91