gondor
gondor

Reputation: 13

Django static files once again not working

I know this question appeared like a milion times, also I'm not a newbie django coder still recently I'm having terrible problems gotting static files work in django projects. Last time I worked around this by using 1.3 but now I'm working on 1.2.5 version and none of the solutions works.

So basically I have statics worknig only in admin section and nowhere else around the site. Static files are in K:/project/media, I'm using window, python 2.7 and django 1.2.5 and the development server.

Settings :

MEDIA_ROOT = path.join(path.abspath(path.dirname(__file__)), 'media')
MEDIA_URL = '/static/'
ADMIN_MEDIA_PREFIX = '/admin_media/'

URLconf :

urlpatterns += patterns('',
    (r'^static/(?P<path>.*)$', 'django.views.static.serve',
        {'document_root': 'K:/project/media/', 'show_indexes': True}
    ),
)

Now when I open http://127.0.0.1:8000/static/ instead of static files list I'm getting TemplateDoesNotExist at /static/. And imports in template return similar error instead of 404 : TemplateDoesNotExist at /static/css/global.css/ . What am I missing here ?

EDIT

Full URL conf

from django.conf.urls.defaults import *
from django.views.generic.simple import redirect_to
from p.globals import views
from p.newsevents.feeds import ReleaseFeed
import filebrowser

# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()

feeds = {
    'releases': ReleaseFeed,
}

urlpatterns = patterns('',

    (r'(?P<reqPath>[\w\-,.]+)$', redirect_to, {'url': '%(reqPath)s/'}),

    (r'^admin/filebrowser/', include('filebrowser.urls')),
    #(r'^admin$', redirect_to, {'url': '/admin/'}),
    (r'^admin/', include(admin.site.urls)),
    (r'^tinymce/', include('tinymce.urls')),
    #(r'^about-us/$', redirect_to, {'url': '/about-us/our-story/'}),
    (r'^feeds/(?P<url>.*)/$', 'django.contrib.syndication.views.feed', {'feed_dict': feeds}),
    (r'^get-your-look/', include('p.getyourlook.urls')),
    (r'^about-us/', include('p.aboutus.urls')),
    (r'^our-services/', include('p.services.urls')),
    (r'^news-events/', include('p.newsevents.urls')),
    (r'^promotions/', include('p.promotions.urls')),
    (r'^careers/', include('p.careers.urls')),
    (r'^locations/', include('p.locations.urls')),

    (r'^$', views.home),
    (r'^(?P<reqPath>[\w\-,.]+)/', views.globals_views),
)

from django.conf import settings

urlpatterns += patterns('',
    (r'^static/(?P<path>.*)$', 'django.views.static.serve',
        {'document_root': 'K:/Kuba/Webdesign/hair/media/', 'show_indexes': True}
    ),
)

Upvotes: 1

Views: 1673

Answers (1)

Aldarund
Aldarund

Reputation: 17621

I guess it`s because of this:

 (r'^(?P<reqPath>[\w\-,.]+)/', views.globals_views),

It will intercept all request to static, and will call that view, which will cause TemplateDoesNotExist error. Put a static url before this or change this( and in urls that it refers to) regex.

Upvotes: 1

Related Questions