Django preventing the loading of django-compressor if DEBUG is True - django

I am using django-compressor with a remote site on an Ubuntu server.
In my local environment, I'm on Windows, where django-compressor doesn't work.
Therefore I can't load django-compressor in my installed apps in my development settings (I have a settings folder with a base.py with dev.py and prod.py inheriting from that).
The problem is in my base.html template where I need to load the compress module
{% load compress %}
at the top of the document, and of course compress my css and js files accordingly.
Clearly this doesn't work on my local environment, with DEBUG set to True because the app can't exist in my installed apps. What I am trying to do is prevent this app being loaded dependent on the value of settings.DEBUG. I have tried an assignment tag which returns settings.DEBUG but that doesn't work.
Is this possible to achieve?
Many thanks in advance.

check out https://pypi.python.org/pypi/django-friendly-tag-loader/.
However, in theory django-compressor should work under windows, although it is not tested and might be broken at the moment. you could find out what the problem is and open a bug report or fix the issue.

Related

I have deployed my Django App on Microsoft Azure and Static files are not displaying, only html

I've deployed a Django app on Azure and run it, everything was working fine css, images, js. After i run Gunicorn to automate the site then Only skeleton HTML displayed, css, images and js disappeared.
this is the Erro:
/home/honest/venv/lib/python3.6/site-packages/django/core/handlers/base.py:58: FutureWarning: TemplateForDeviceMiddleware is deprecated. Please remove it from your middleware settings.
mw_instance = mw_class()
/home/honest/venv/lib/python3.6/site-packages/django/core/handlers/base.py:58: FutureWarning: TemplateForHostMiddleware is deprecated. Please upgrade to the template loader.
Not Found: /static/images/sample/slider/img7.png/
May i know if i need to configure WhiteNoise for gunicorn on Azure?
Do i Need to edit my HTML templates to point to static folder in Azure?
I tried some of the solutions i saw here like setting DEBURG to True set path for static files in Settings.py but it couldn't help.
I will be glad receiving a step by step solution to this.
Thanks for the assistence.

including foundation with sass in a django project

I have a django project under a virtualenv.
I included the django-zurb-foundation 5.3.0 package to use foundation but this version only include static css files.
It's my first time using django and normally i use foundation with sass using bower and grunt.
How can i do to use the sass version of foundation?
What should be the files tree?
UPDATE
i installed django compressor and i got it work on local, it works perfectly, but i cannot get it to work on my production server:
on local env i have a CACHE folder with the css static files in it and the html page call correctly the file from there.
On the prod site instead, it doesnt create the CACHE folder and it doesnt render the path to it and it keeps the path to the scss file.
What am i doing wrong?
It seems like compressor isnt working on the prod server, i'm afraid i'm doing something wrong with django settings.py since i'm new to it.
any help?
I have heard of a few people using django-bower with foundation, personally I have not played with it but its worth looking into if you have not already.
I really can't find a reason to use a third party Django application to do that, using front-end frameworks like foundation or Bootstrap is as simple as compiling the less or sass source files to a css file and include it in your html (<link rel="stylesheet"...).
With Django you can use Bower and Grunt without any problem because they're independent and totally configurable to fill your needs. What I do with bower is to create a .bowerrc file at the same level of the bower.json file with the directory setting pointing to the main static folder, something like:
{
"directory": "my_django_app/static/bower_components"
}
Talking about the django-compressor app all that I can say is I don't recommend to use it in a production environment, it has some performance problems and personally I prefer the static files to be responsibility of the front-end dev instead of the back-end dev. For example you will need to have source maps for your javascript for debugging purposes and I don't remember if it's possible with this plugin.
Instead of using the django-compressor you can use a grunt plugin to to it, I've done one that may help you to do so: https://www.npmjs.org/package/grunt-django-compressor

Django: STATIC_* and MEDIA_* all identical, but app still runs in production

I'm currently working on a Django 1.3 app where both MEDIA_ROOT and STATIC_ROOT are identical, and MEDIA_URL and STATIC_URL are identical.
This (somehow) runs on the production server, but locally when I call manage.py runserver I get an ImproperlyConfigured exception and can only run the application when I override the settings so that MEDIA_* is different from STATIC_* (DEBUG=False just gives a 500). This is what I would expect to happen (as per documentation), and so I don't understand how they can get it working in Production.
The original developer of the application has moved on so I can't ask any questions as how they've managed to get this to work. Is there a known method of circumventing Django's static and media file separation?
Not a great answer as it's so specific, but the answer was that they just never run the application with DEBUG=True (runserver will run happily with DEBUG=False and incorrect MEDIA_* and STATIC_* settings). There was no silver bullet, the application appears to be debugged using the error log created by mod_wsgi (no logging in place). I assume that this also how the development environment was set up.
The application is also notable for being run whilst not being on the PYTHONPATH, and having all of its apps in a separate folder in another part of the filesystem. This was discovered when adding a new application to the folder containing manage.py and having import errors for the new application. I think this was so that multiple django installations could use the same set of apps.
Thanks to Yuji for his help .

Weird deployment issue with Django and CoffeeScript to Heroku

This is sort of a complex question so it will take a bit to explain. I'm not looking for a direct answer so any advice would be good. I have a Django app that uses a lot of CoffeeScript. To compile the CoffeeScript in the project I am using the app django-compressor. To use django-compressor I need to install nmp (node package manager). Unfortunately, I can't install npm on Heroku. Thus, I need to compile the CoffeeScript before it hits the Heroku servers. So I did that by setting up Fabric which is seeming to work well.
I am running into a problem no because I can get the compiled CoffeeScript as a static file but the templates still have the {% compress js %} *** {% endcompress %} tags in them because django-compressor does not regenerate new templates until run time.
Thus I am looking for advice on how to deploy the app to get ride of the template tags so that the app can be deployed on Heroku. I know it is a question with a lot of parts so any piece of advice would be super helpful!
I realize it's quite an old question - hit it occasionally
Just in case, here's the way to deal:
http://django_compressor.readthedocs.org/en/latest/usage/#pre-compression
http://django_compressor.readthedocs.org/en/latest/scenarios/#offline-compression
you could also commit the manifest.json file that django compressor generates (I'm assuming you're using it in offline mode) and then it will know which template blocks go to which compiled js/css files

after upgrade to python2.6 and ubuntu 9.0, django admin does not load css even though admin media is properly configured

basically i upgraded ubuntu to juanty, and with it came python2.6 so i decided to take the chance and make django work with it. i re-svn'd django into dist-packages, and made sure to properly sym-link my admin media. Note that i'm not using apache, rather just the django development server.
when i load up the admin the css seems to not take effect, when i view source it is calling the proper files and i even go ahead and load these files in the browser and they load properly.
any ideas as to what i've done wrong? i'm thinking it has to do with using the latest revision of django.
-------------Edit--------------------
to answer your questions below:
I am not running apache, i'm serving static files using django and i've tried loading the files from the browser and they work fine.
i did this in my settings file
ADMIN_MEDIA_PREFIX = '/static/admin_media/'
i symlinked from my static folder admin_media > /usr/lib/python2.6/dist-packages/django/contrib/admin/media/
this is really stumping me as i think i've done everything right.
------------Edit------------
heres a sample of my urls.py
(r'^static/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT}),
what i've recalled is that before (in ubuntu 8 & probably an older svn revision of django) i didn't configure anyting in my settings or symlin anything from my static folder and it worked just fine with the default /media/ - is there somewhere where it is symlinked automatically for the admin?
------Edit-------------------
This is most likely a bug with the svn version, as after this i tried on my windows machine and i get the same thing. the css files are linked properly but are not imported. instead when i click on them it downloads the files. permission issue anyone?
help, as the admin doesn't look as nice without the css formating.
Are you running under Apache? Depending on what earlier version of Ubuntu you upgraded from, some Apache configs might have changed. I have a vague recollection of having had a problem upgrading from dapper to 8.10 that was solved by adding a block to /etc/apache2/httpd.conf
I am using python 2.6.2 on jaunty and the latest django svn reversion (rev. 10857) and don't have any problems.
Can you supply more details? For example, what did you set in your settings.py, how did you configure your urls.py, are you using django to serve the media files, what is the output from the debug server when you load the admin interface, do you get any errors, etc.
Have you tried requesting the files directly or used firebug (checking for 404's and the like)?
Edit:
A little unrelated but, you may want to make your project more portable/reusable by using relative paths.
#settings.py
import os
PROJECT_PATH = os.path.abspath(os.path.dirname(__file__))
DEBUG = True
SERVE_MEDIA = DEBUG
MEDIA_ROOT = os.path.join(PROJECT_PATH, 'static')
MEDIA_URL = '/static/'
ADMIN_MEDIA_PREFIX = '/media/'
wow, i don't want to come across as an answer spammer for answering my own questions but... nobody else seemed to answer the questions and i then tend to figure them out by myself. ugghh..
anways the answer to the above is simple, quite simple
since i had created the above django projects using an older version of django and not the latest svn version, you need to overwrite or delete the old admin media directory under static and the admin templates. in my case i just deleted the admini media and admin templates and voila ... the admin was back!!!
can't believe i hadn't tought of that before.