Pregunta

I am using django 1.3 and trying to deploy a django project (client sent) on my dev machine (ubuntu 12.04). The problem is regarding the static files. My directory structure is as follows:

project_name
    media
    static
        css
        img
        js
    settings.py

Here is my settings.py:

ROOT = '/home/user/project_name'

MEDIA_ROOT = '%s/media/' % ROOT
MEDIA_URL = '/media/'
STATIC_ROOT = '%s/static/' % ROOT
STATIC_URL = '/static/'
STATICFILES_DIRS = ()

My site is perfectly deployed but the css, js and imgs are missing. Same is the case for the admin interface. When I use the link http://mysite.com/static/js/some.js it gives a 404.

Help would be appreciated and up-voting an answer is custom.

¿Fue útil?

Solución 2

You don't mention configuring your web server to actually serve the static files. You need to point it at the directory that collectstatic put them into.

Otros consejos

I think you need to run ./manage.py collectstatic :)

did you run python manage.py collectstatic ? see here

be careful that in production you should place the static file in a static server. There should be something in the guidelines.

And a little offtopic..
It will be better, to use:
MEDIA_ROOT = os.path.join(os.path.dirname(file),'media').replace('\','/')
STATIC_ROOT = os.path.join(os.path.dirname(file),'static').replace('\','/')

and in main urls.py at development, django webserver only:
urlpatterns = patterns('', (r'^media/(?P.*)','django.views.static.serve',{'document_root': os.path.join(os.path.dirname(file),'media').replace('\','/') }),
(r'^static/(?P.*)','django.views.static.serve',{'document_root': os.path.join(os.path.dirname(file),'static').replace('\','/')}),

In this way, u dont need collectstatic, ull need it at production server, where u will use nginx or something other to server your static

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top