I am unable to get my static files to work. I've spent 6 hours looking at the many posts on this topic but I must still be doing something wrong. Please help. Here are my settings:
projectfiles
|
|-----myproject
| |
| |-----static
| | |
| | |-----css
| | |-----js
| |-----__init__.py
| |-----settings.py
| |-----urls.py
| |-----wsgi.py
|
|-----myapp
|
|-----templates
settings.py
import os
SITE_ROOT = (os.path.realpath(os.path.dirname(__file__))).replace('\\','/')
DEBUG = True
MEDIA_ROOT = (os.path.join(SITE_ROOT, '/static')).replace('\\','/')
MEDIA_URL = '/static/'
STATIC_ROOT = ''
STATIC_URL = ''
STATICFILES_DIRS = ()
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
'django.contrib.staticfiles.finders.DefaultStorageFinder',
)
urls.py
urlpatterns = patterns('',
(r'^myurl/$', myview),
)
from myproject.settings import DEBUG
if DEBUG:
urlpatterns += patterns('', (r'^static/(?P<path>.*)$', 'django.views.static.serve',
{'document_root': 'static'}))
mytemplate.html
...
<head>
<link src="css/mycss.css" rel="stylesheet" type="text/css"/>
...
the app works fine but no connection to my css's or javascripts. What am I misssing?
Any help would be sooo greatly appreciated.
Update:
`STATIC_ROOT='C:/path/to/myproject/static/'
STATIC_URL='/static/'
TEMPLATE_CONTEXT_PROCESSORS=('...static', )
STATICFILES_DIRS=('C:/absolute/path/to/myapp/static',)
STATICFILES_FINDERS=('...FileSystemFinder','...AppDirectoriesFinder',)
INSTALLED_APPS = (...,'django.contrib.staticfiles',)
#does not work with or without this:
urlpatterns += staticfiles_urlpatterns()
#views now rendered like this:
myview(request):
...
return render_to_response('template.html',{'a': a},context_instance =RequestContext(request))
#template.html
<link src="{{STATIC_URL}}css/mycss.css"/>
MEDIA_ROOT AND MEDIA_URL are not used for serving static content with advent of the staticfiles app from django 1.3 so, I suggest using STATIC_URL and STATIC_ROOT instead to configure the static files.
Using Django version 1.6; STATIC_URL cannot be a stem; Not sure when this changed.
The following type of specification in
settings.py
gives a 404:This works: