在settings.py中:
import osCURRENT_PATH = os.path.abspath(os.path.dirname(__file__).depre('utf-8'))MEDIA_ROOT = os.path.join(CURRENT_PATH, 'media')MEDIA_URL = '/media/'STATIC_ROOT = 'static/'STATIC_URL = '/static/'STATICFILES_DIRS = ( os.path.join(CURRENT_PATH, 'static'),)然后将你的js和css文件静态文件夹放置在你的项目中。不在媒体文件夹中。
在views.py中:
from django.shortcuts import render_to_response, RequestContextdef view_name(request): #your stuff goes here return render_to_response('template.html', locals(), context_instance = RequestContext(request))在template.html中:
<link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}css/style.css" /><script type="text/javascript" src="{{ STATIC_URL }}js/jquery-1.8.3.min.js"></script>在urls.py中:
from django.conf import settingsurlpatterns += patterns('', url(r'^media/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT, 'show_indexes': True}),)项目文件结构可以在imgbin中找到。


![在我的Django模板中包含CSS和Javascript [重复] 在我的Django模板中包含CSS和Javascript [重复]](http://www.mshxw.com/aiimages/31/371101.png)
