Django-compressor not working after first compress statement - django

I have a website with various js files, and i'm using django-compressor like so:
{% compress js %}
{% endcompress %}
{% compress js %}
{% endcompress %}
For some reason its only creating the FIRST js file. I have my app hosted on an EC2. I can see the first file there. The second file appears when I do a view source on the page, however, the file itself doens't exist (I get a 404 when I click on the link to the second js file). Is there anything I'm doing wrong? I have my settings as per below:
COMPRESS_ENABLED = not DEBUG
COMPRESS_PARSER = 'compressor.parser.BeautifulSoupParser'
COMPRESS_CSS_FILTERS = ['compressor.filters.cssmin.CSSMinFilter']
COMPRESS_JS_FILTERS = ['compressor.filters.jsmin.JSMinFilter']
It's working perfectly for css files...but failing on any other js file after the first compress flag...

I honestly have no idea what happened. this used to work perfectly, but randomly stopped out of no where! I did the following and it worked:
python manage.py compress --force
This basically forces it to compress all files; normally django-compressor ignores files that have not changed and have been compressed already.

Related

TemplateSyntaxError: Templates and static files

I have components for the website and they all work fine, for example I have a navbar.html and works flawlessly. However, I think the issue begins when I have a static file. I have another component called 'header.html' (which contains a profile picture) and SHOULD have loaded up a header in my index.html file. But it spits 'TemplateSyntaxError' and says that the issue is with the line code '{% static ... %}'.
My settings.py seems correct (see below). I also included 'django.contrib.staticfiles' and {% load static %} in the main index.html.
This is also the html part:
The structure of my project is as such:
-myproject
--base
--myproject
--static
--staticfiles
Did you load static on the template?
Add {% load static %} to the top of your html file

ckeditor: Cannot set property 'dir' of undefined (django + zinnia)

I am experiencing this strange error only on my production environment. It works fine locally and on staging.
I'm using Django==1.10.5 & django-blog-zinnia==0.18.1 with zinnia-wysiwyg-ckeditor==1.3. I believe this issue happened recently when we upgraded from Django==1.8 to the latest.
When I try to create a blog entry, I can't edit the content because the ckeditor instance does not load. The errors are:
https://example.com/admin/zinnia/entry/81/change/config.js/change/ 404 (Not Found)
https://example.com/admin/zinnia/entry/81/change/lang/en.js/change/
GET https://example.com/admin/zinnia/entry/81/change/skins/moono-lisa/editor.css/change/
Uncaught TypeError: Cannot set property 'dir' of undefined
The URL is /admin/zinnia/entry/81/change/
So this very much looks like ckeditor.js is trying to load additional static files based on the current URLs and somehow it injects the filenames into the current URL.
As a workaround, I ssh-ed into the server and manipulated /static/ckeditor/ckeditor/ckeditor.8bd276b5ef4c.js and added this line at the very top:
window.CKEDITOR_BASEPATH = '/static/ckeditor/ckeditor/';
This solves the issue. The big question is: Why does this only happen on one of my machines, why does Django/zinnia not set CKEDITOR_BASEPATH correctly by itself?
I'm posting this here because I am not sure if this is an issue in Django, zinnia or zinnia-ckeditor, if anyone got insights on who is guilty, I'm happy to re-post this issue on the relevant issue tracker on github.
EDIT:
As a workaround, in my project I created the file templates/admin/change_form.html:
{% extends "admin/change_form.html" %}
{% block extrahead %}
<script>window.CKEDITOR_BASEPATH = '/static/ckeditor/ckeditor/';</script>
{{ block.super }}
{% endblock %}

sphinx overrided template block not recognized

I'm attempting to add a link to an icon I used to the footer of my doc page, but I can't seem to figure out how to copy this link. I'm following this tutorial but haven't had any luck. I've created a file _templates/layout.html:
{% extends "!layout.html" %}
{% block footer %}
<li>CC BY 3.0</li>
{{ super() }}
{% endblock %}
then in my conf.py I do
templates_path = ['_templates']
# ...
html_theme = 'sphinx_rtd_theme'
The problem is that when I build, nothing extra shows up in the footer of my page. I initially thought sphinx just wasn't finding my file, but if I change {% extends "!layout.html" %} to {% extends "layout.html" %} I get the error
Running Sphinx v1.3.1
loading pickled environment... done
building [mo]: targets for 0 po files that are out of date
building [html]: targets for 30 source files that are out of date
updating environment: 0 added, 0 changed, 0 removed
looking for now-outdated files... none found
preparing documents... done
writing output... [ 3%] dev/conventions
Exception occurred:
File "C:\...\Anaconda\lib\site-packages\jinja2\utils.py", line 389,
in __getitem__
if self._queue[-1] != key:
RuntimeError: maximum recursion depth exceeded in cmp
The full traceback has been saved in c:\...\appdata\local\temp\1\sphi
nx-err-tjhk_m.log, if you want to report the issue to the developers.
Please also report this if it was a user error, so that a better error message c
an be provided next time.
A bug report can be filed in the tracker at <https://github.com/sphinx-doc/sphin
x/issues>. Thanks!
So I know sphinx see's my file, but it doesn't seem to write anything. What am I doing wrong?
The issue I ended up having was I was overwriting the wrong file, while layout.html did implement a footer block, it was not the block I was looking to add to. Instead sphinx_rtd_theme has a footer.html file, which I ended up overwriting instead and everything worked as intended.

Django and OpenShift static files can't be found

So I followed this tutorial:
https://github.com/rancavil/django-openshift-quickstart/wiki/Tutorial-How-create-an-application-with-Django-1.6-on-Openshift
and I tried to add a static image to the default home.html page and it just won't find it.
HTML:
{% load static %}
<html>
<head>
</head>
<body>
<img src="{% static 'Logo_Trans.png' %}">
<div class="left"></div>
<div class="right">
<p>is coming soon</p>
</div>
</body>
</html>
All other files are as listed in the repo given.
I've found the problem. The static files were serving properly when deployed but not when in debug mode. To fix this just add the STATICFILES_DIR variable in settings.py
Find:
if ON_OPENSHIFT:
DEBUG = False
else:
DEBUG = True
Add:
if ON_OPENSHIFT:
DEBUG = False
else:
DEBUG = True
STATICFILES_DIRS = (os.path.join(BASE_DIR, "static"),
'/var/www/static/',)
Openshift is a very good service but definitely needs to update their docs/examples for django. Their sample program still runs django 1.4. Hope this helps anyone else that runs into this problem.
you can read the answer for this question Django cannot find static files. Need a second pair of eyes, I'm going crazy. Hope it will help you to understand static files. Static files in Django are always a bit painful.
Btw, as I explain in the last comment, I recommend you to create an app called common within a static folder inside it to place static content that is not application specific. Static application specific files should be placed inside the static folder within your app. This way, you can forget about defining the STATICFILES_DIRS variable and it will always work in DEBUG mode.
After that, ofc, define STATIC_ROOT and when you want to work in deploy mode, do the collectstatic command and it will also work.
After dealing hundreds of times with issues like this, I've found this is the best approach.

Angular JS + Django - Referencing static files

I've written my first angular app for handling a rather complex multi-file upload process within a Django app. Everything is working great and I'm loving Angular. However, I stumbled on a simple problem referencing image sources. It's not critical for my app, but I wanted to add a simple spinner/whirligig image while the files are uploading.
In my non-Angular Django templates this is dead simple:
<img src='{% static 'whirligig.gif' %}'>
This doesn't work inside Angular views due to the Angular/Django template syntax conflict. Of course, I can hard-code my Django STATIC_URL path or use a relative path from the Angular partial, but I'd prefer not to. Am I missing something simple here or is this just an unfortunate product of mixing two MVC frameworks?
Have you tried verbatim tag?
I guess you can do something like:
{% verbatim %}{{ {% endberbatim %}{% static 'whirligig.gif' %}{% verbatim %} }}{% endverbatim %}