Files in MEDIA_ROOT not getting accessed on Windows

262 views
Skip to first unread message

Aaron

unread,
Sep 25, 2009, 2:59:33 PM9/25/09
to Django users
I have a Django 1.1 project under Windows, and I am using an app that
uses JavaScript (specifically, Page CMS). The JavaScript is in the js
folder of the media folder, and I've set MEDIA_ROOT in my settings to
the full path to the media folder (with backslashes replaced by
forward slashes). MEDIA_URL is blank.

The problem is that the JavaScript isn't working. When I go to a page
with controls that use JavaScript, the controls aren't there and
there's a "jQuery is not defined" error in my browser's error console.

The strange thing is that the same code works perfectly on our Linux
machines with no apparent differences to the configuration beyond the
the contents of MEDIA_ROOT.

Karen Tracey

unread,
Sep 25, 2009, 7:19:15 PM9/25/09
to django...@googlegroups.com

You don't say how you are serving these files.  Are you running the development server?  If so what does your static server config look like?

Karen

Aaron

unread,
Sep 28, 2009, 8:16:39 AM9/28/09
to Django users
On Sep 25, 8:19 pm, Karen Tracey <kmtra...@gmail.com> wrote:
> You don't say how you are serving these files.  Are you running the
> development server?  If so what does your static server config look like?

Yes, this is on the development server. The one you get by running
"python manage.py runserver".

If by static server config you mean my settings.py file, this is what
it looks like:

DEBUG = True
TEMPLATE_DEBUG = DEBUG

ADMINS = (
...
)

MANAGERS = ADMINS

DATABASE_ENGINE = 'sqlite3'
DATABASE_NAME = 'C:/path/to/db/data.db'
DATABASE_USER = ''
DATABASE_PASSWORD = ''
DATABASE_HOST = ''
DATABASE_PORT = ''

TIME_ZONE = ...

LANGUAGE_CODE = 'en-us'

USE_I18N = True

MEDIA_ROOT = 'C:/path/to/media'
MEDIA_URL = ''

ADMIN_MEDIA_PREFIX = '/media/'

...

TEMPLATE_CONTEXT_PROCESSORS = (
...
'pages.context_processors.media',
)

INSTALLED_APPS = (
...
'pages', #apps.external.pages
)

Karen Tracey

unread,
Sep 28, 2009, 8:38:56 AM9/28/09
to django...@googlegroups.com
On Mon, Sep 28, 2009 at 8:16 AM, Aaron <aa...@genieknows.com> wrote:

On Sep 25, 8:19 pm, Karen Tracey <kmtra...@gmail.com> wrote:
> You don't say how you are serving these files.  Are you running the
> development server?  If so what does your static server config look like?

Yes, this is on the development server.  The one you get by running
"python manage.py runserver".

If by static server config you mean my settings.py file, this is what
it looks like:


No, I mean the config for the static server:

http://docs.djangoproject.com/en/dev/howto/static-files/

The Django development server does not serve static files out of MEDIA_ROOT by default, you have to configure the static server to do this.

Karen

Aaron

unread,
Sep 28, 2009, 10:30:09 AM9/28/09
to Django users
On Sep 28, 9:38 am, Karen Tracey <kmtra...@gmail.com> wrote:
> No, I mean the config for the static server:
>
> http://docs.djangoproject.com/en/dev/howto/static-files/
>
> The Django development server does not serve static files out of MEDIA_ROOT
> by default, you have to configure the static server to do this.

Well, I have this in my URLconf:

(r'^site_media/(?P<path>.*)$', 'django.views.static.serve',
{'document_root': settings.MEDIA_ROOT}),

I don't know what else I'd have to do.

Karen Tracey

unread,
Sep 28, 2009, 11:23:02 AM9/28/09
to django...@googlegroups.com

You need to ensure that the requests for your JavaScript files match the pattern you have specified here for files to be served by the static server.  Earlier you said your MEDIA_URL is blank, which may be the problem.  If you are using MEDIA_URL to construct the path to your JavaScript files then to match that pattern, MEDIA_URL should be '/site_media/'. 

Note you should be able to see the requests for the JavaScript files logged in the development server console.  What do they look like?

Karen

Aaron

unread,
Sep 28, 2009, 12:23:00 PM9/28/09
to Django users
On Sep 28, 12:23 pm, Karen Tracey <kmtra...@gmail.com> wrote:
> You need to ensure that the requests for your JavaScript files match the
> pattern you have specified here for files to be served by the static
> server.  Earlier you said your MEDIA_URL is blank, which may be the
> problem.  If you are using MEDIA_URL to construct the path to your
> JavaScript files then to match that pattern, MEDIA_URL should be
> '/site_media/'.
>
> Note you should be able to see the requests for the JavaScript files logged
> in the development server console.  What do they look like?

O.K. I've set MEDIA_URL to '/site_media/'. This is what's turning up
in the console when I open a page using Javascript (specifically, the
'Add Page' form for Pages CMS):

----------

[28/Sep/2009 13:18:33] "GET /admin/pages/page/add/ HTTP/1.1" 200 13403
[28/Sep/2009 13:18:33] "GET /admin/jsi18n/ HTTP/1.1" 200 803
[28/Sep/2009 13:18:33] "GET /site_media/pages/css/rte.css HTTP/1.1"
304 0
[28/Sep/2009 13:18:33] "GET /site_media/pages/css/pages.css HTTP/1.1"
304 0
[28/Sep/2009 13:18:33] "GET /site_media/pages/javascript/jquery.js
HTTP/1.1" 304
0
[28/Sep/2009 13:18:33] "GET /site_media/pages/javascript/jquery.rte.js
HTTP/1.1"
304 0
[28/Sep/2009 13:18:33] "GET /site_media/pages/javascript/
jquery.query.js HTTP/1.
1" 304 0
[28/Sep/2009 13:18:33] "GET /site_media/pages/javascript/pages.js HTTP/
1.1" 304
0
[28/Sep/2009 13:18:33] "GET /site_media/pages/javascript/pages_form.js
HTTP/1.1"
304 0
[28/Sep/2009 13:18:33] "GET /site_media/pages/javascript/
jquery.bgiframe.min.js
HTTP/1.1" 304 0
[28/Sep/2009 13:18:33] "GET /site_media/pages/javascript/
jquery.ajaxQueue.js HTT
P/1.1" 304 0
[28/Sep/2009 13:18:33] "GET /site_media/pages/javascript/
jquery.autocomplete.min
.js HTTP/1.1" 304 0

Aaron

unread,
Sep 28, 2009, 12:31:08 PM9/28/09
to Django users
Sorry for the double post, but I forgot to mention something else.
Ever since I changed MEDIA_URL to '/site_media/' I no longer get the
"jQuery is not defined" error. However, I get a different set of
errors:

Warning: Error in parsing value for 'filter'. Declaration dropped.
Source File: http://localhost:8000/site_media/pages/css/pages.css
Line: 181
Warning: Error in parsing value for 'filter'. Declaration dropped.
Source File: http://localhost:8000/site_media/pages/css/pages.css
Line: 185
Warning: Error in parsing value for 'filter'. Declaration dropped.
Source File: http://localhost:8000/site_media/pages/css/pages.css
Line: 222
Warning: Error in parsing value for 'vertical-align'. Declaration
dropped.
Source File: http://localhost:8000/site_media/pages/css/pages.css
Line: 234

Also, ever since I've set MEDIA_URL the layout of some of my pages has
changed, and it seems they are now accessing the static files such as
the CSS files they were supposed to access.

Karen Tracey

unread,
Sep 28, 2009, 1:26:12 PM9/28/09
to django...@googlegroups.com

The numbers following the request path and HTTP version are the HTTP status code returned and the size of the response.  It looks like all of your requests for .js files are getting HTTP 304 returned, with a 0 byte response.  HTTP 304 is "Not modified".   So the development server is responding to a client that is sending if-modified-since with a response saying the file hasn't been modified since whenever the client has specified. 

That is, this all looks like everything is working properly.  At some point before these lines it appears that the javascript files were delivered successfully to the client.  Is your javascript really still not working at all?

Karen

Karen Tracey

unread,
Sep 28, 2009, 1:30:10 PM9/28/09
to django...@googlegroups.com
On Mon, Sep 28, 2009 at 12:31 PM, Aaron <aa...@genieknows.com> wrote:

Sorry for the double post, but I forgot to mention something else.
Ever since I changed MEDIA_URL to '/site_media/' I no longer get the
"jQuery is not defined" error. However, I get a different set of
errors:

Warning: Error in parsing value for 'filter'.  Declaration dropped.
Source File: http://localhost:8000/site_media/pages/css/pages.css
Line: 181
Warning: Error in parsing value for 'filter'.  Declaration dropped.
Source File: http://localhost:8000/site_media/pages/css/pages.css
Line: 185
Warning: Error in parsing value for 'filter'.  Declaration dropped.
Source File: http://localhost:8000/site_media/pages/css/pages.css
Line: 222
Warning: Error in parsing value for 'vertical-align'.  Declaration
dropped.
Source File: http://localhost:8000/site_media/pages/css/pages.css
Line: 234


These appear to be errors in your css files.  It seems that now that you have set things up so that your css files are actually being served, you are seeing errors reported about them.  You wouldn't have seen these earlier because your css files were not being served by the development server.
 
Also, ever since I've set MEDIA_URL the layout of some of my pages has
changed, and it seems they are now accessing the static files such as
the CSS files they were supposed to access.

 
So that sounds like things are working as they should be now?  You are just getting notified of problems that could not be noticed earlier, since the files weren't being served.

Karen

Aaron

unread,
Sep 28, 2009, 2:41:39 PM9/28/09
to Django users
It actually is working now. The files that were being served were just
outdated, and everything started working perfectly after I replaced
them with updated ones.

Thank you.
Reply all
Reply to author
Forward
0 new messages