I am learning Django for one of my web projects. Before adding a css, jquery project to my project. The template is very simple and there is no need to use extends. Just one page. What I did to declare my media file: In the settings.py file: Added path:
`import os def path(*x): return os.path.join(os.path.abspath(os.path.dirname(__file__)), *x)
`Then added:
MEDIA_ROOT = path('media') #media is my folder where all the css,js file are MEDIA_URL = '/media/' ADMIN_MEDIA_PREFIX = '/media/' TEMPLATE_DIRS = ( path('templates')
In the added urls.py file:
from django.conf import settings urlpatterns = patterns('', (r'^media/(?P<path>.*)$', 'django.views.static.serve', { 'document_root' : settings.MEDIA_ROOT }),
In the template file, I tried using all of these types of declarations:
<script type="text/javascript" src="/media/jquery.min.js"></script> <script type="text/javascript" src="/media/site.js"></script> <link rel="stylesheet" type="text/css" media="screen" href="/media/screen.css" /> <link rel="stylesheet" type="text/css" href="{{ MEDIA_URL }}test.css" /> <link rel="stylesheet" type="text/css" media="screen" href="../media/screen.css" />
But when I downloaded the template file as plain html with:
<script type="text/javascript" src="../media/jquery.min.js"></script> <script type="text/javascript" src="../media/site.js"></script> <link rel="stylesheet" type="text/css" media="screen" href="../media/screen.css" />
It worked. But I need to integrate into my Django project. Hope will get the navigation and solve it :) Thanks
source share