In a Django app, where should I put my javascript/jquery scripts?
Adding JavaScript to Our Django Template js file, put it in a js folder that you need to create in the static folder of your application. We use the static template tag to specify the relative URL to the JS file.
To load JavaScript file, just add the following line of code in index. html file. Run the server by using python manage.py runserver command. After that access the template by localhost:8000/index URL, and it will produce the following output to the browser.
While most of Django core is Python, the admin and gis contrib apps contain JavaScript code. Please follow these coding standards when writing JavaScript code for inclusion in Django.
django. contrib. staticfiles collects static files from each of your applications (and any other places you specify) into a single location that can easily be served in production. For an introduction to the static files app and some usage examples, see How to manage static files (e.g. images, JavaScript, CSS).
In with your other static media. See here for more info:
http://docs.djangoproject.com/en/dev/howto/static-files/
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'))
Following that structure the path structure should be:
-yourApp
----manage.py
----media
----static
----yourApp
--------settings.py
--------models.py
Django: How to manage static files
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With