1

I am trying to link to a LESS stylesheet with Django. The file is stored in my static folder and all of the javascript and css files are served without a problem.

When I use a '.less' extension on my file, I get the following error:

XMLHttpRequest cannot load...
Origin null is not allowed by Access-Control-Allow-Origin.

When I visit the page directly, a download prompt pops up for the file.

When I take the extension off completely, I get a black screen in my web browser and can't bring up the console in Chrome.

When I use the '.txt' extension I can view the page fine, but still get the same error above when I try to link to it.

<link rel="stylesheet/less" type="text/css" href="static/CSS/BaseLess.txt">
<script src="/Plugins/less-1.3.0.js" type="static/text/javascript"></script>

Any ideas how I can solve this? Let me know if you want to see more Less code or error message.

Edit I was actually serving my less files from a different server and You cannot access data from another server with an XMLHttpRequest.

I switched the file over to the same server and it worked fine with the less extension.

Community
  • 1
  • 1
Eric H.
  • 6,894
  • 8
  • 43
  • 62
  • 1
    1) You need to take the "static/" bit off the script's `type`. That's probably not your problem though. 2) What environment are you running? Is this over `runserver` in dev, or do you have a real webserver in the mix? – Chris Pratt Mar 22 '12 at 19:21
  • I'm in dev mode. I should also add that xhr.send(null) results in this error within the less.js file: `Uncaught Error: NETWORK_ERR: XMLHttpRequest Exception 101` – Eric H. Mar 22 '12 at 19:23
  • 3
    I don't have a solution for you, unfortunately. LESS is pretty much plug and go. FWIW, though, requiring JS to render your site's CSS is a bad way to go in my opinion. It's far superior to preprocess the LESS into actual CSS files either manually or automatically with something like django-compressor. – Chris Pratt Mar 22 '12 at 19:43
  • Ok thanks I'll keep that in mind. I'm brand new to LESS, so I'll prob stick to JS rendering until I have something substantial enough to compile. – Eric H. Mar 22 '12 at 19:48
  • 1
    I second Chris. I always pre-compile my .less to .css before deployment. I dev on Windows, so I use WinLess to watch my less directories and compile/minify as I go. – Brandon Taylor Mar 22 '12 at 21:00

1 Answers1

0

Edit I was actually serving my less files from a different server and You cannot access data from another server with an XMLHttpRequest.

I switched the file over to the same server and it worked fine with the less extension.

Eric H.
  • 6,894
  • 8
  • 43
  • 62
  • On a note for anyone else ending up here: I've gotten the same error on my web host's web server. It was erroneously sending empty responses because the `.less` file/mime type was unknown. Configuring the web server to properly serve .less files fixed it. (It was not a cross-domain request, all `.js`/`.less` files were served from the same folder.) – Joel Purra Jun 24 '12 at 19:45