Possible reason for django template not loading upadted static file - django

<section>
website content here
</section>
{% load static %}
<script src="{% static 'notifications.js' %}" type="text/javascript"></script>
<script src="{% static 'presentation.js' %}" type="text/javascript"></script>
That code worked as it should ie. loading current versions of .js files. After some time I noticed a typo in notifications.js file. After fixing the typo and saving the file local development server is still loading version without fix. I tried clearing browser cache and history as well as rebooting device and problem still occurs. Any possible fix?

Related

Can't see Angular project inside Django

I am trying to run Angular inside Django project. I successfully installed it and have no errors when I run the Django server. However I do not see my Angular. app.component.html. I see my index.html of folder "templates" instead.
templates/index.html
{% extends "base.html" %}
{% load staticfiles %}
{% block content %}
<p>This is a mini-blog application using a back-end built on Django 2.0 and Django Rest Framework. It illustrates how to create and send JSON Web Token authentication headers with the HTTP requests.</p>
<app-root>Loading the app...</app-root>
<script type="text/javascript" src="{% static 'clientapp/runtime.js' %}"></script>
<script type="text/javascript" src="{% static 'clientapp/polyfills.js' %}"></script>
<script type="text/javascript" src="{% static 'clientapp/styles.js' %}"></script>
<script type="text/javascript" src="{% static 'clientapp/vendor.js' %}"></script>
<script type="text/javascript" src="{% static 'clientapp/main.js' %}"></script>
{% endblock %}
Obviously, something is missing.
I am using this tutorial and looks like copied all the setttings:
https://www.metaltoad.com/blog/angular-api-calls-django-authentication-jwt
Thanks in advance.
In Django, Angular is nothing more than a set of static files.
So in order to make sure everything falls in its place, we need to load static files in order of their preference.
I suggest you visit index.html generated by webpack, just copy that order of javascript files in Django index.html in Django format.
For More info visit your browser console for errors.
For Ref: https://github.com/deepak1725/djangular
Sometimes the problem is absolutely silly as in my case.
I used old ng build.
Each time after change links to static files we need to run ng build

Django Compressor : cache messing up

I have a webapp using django-compressor for js, css and less minification.
I'm using COMPRESS_OFFLINE = True because I'm using django compressor to build a less file containing import to other files (otherwise django compressor does not rebuild files if make change in core.less):
// base.html
{% compress css %}
<link rel="stylesheet" type="text/less" media="all" href="{% static 'less/main.less' %}" />
{% endcompress %}
// main.less
#import "core.less";
#import "variables.less";
#import "utils.less";
#import "sidebar.less";
I am running into the following issue: i have the following .css files in assets/CACHE/css:
2601cbccb2ae.css
52a7aa59f552.css
729b9866970c.css
They are all corresponding to a modification of my core.less file. The issue is that when I log in my webapp, it seems Django-Compress {%compress%} use all those file and not only the last one. So sometimes I have the good design, and if I refresh I got the old one...
// First time the page is ok:
<link href="/static/CACHE/css/2601cbccb2ae.css" media="all" rel="stylesheet" type="text/css"/>
// After reloading I got the old design
<link href="/static/CACHE/css/52a7aa59f552.css" media="all" rel="stylesheet" type="text/css"/>
Each time I refresh the file changes... So I assume there is something related to django compressor cache but I have really no idea how to solve this...
If you guys have an idea, feel free to help me.

Can't get django-inplaceedit to work

The top of my HTML template contains:
{% load inplace_edit %}
Header part contains:
{% inplace_static %}
Then in my body contents I am doing:
{% inplace_edit "action.action_state" %}
But it's not working. I have installed:
'bootstrap3',
'inplaceeditform_bootstrap', # it is very important that this app is placed before inplaceeditform and inplaceeditform_extra_fields
'inplaceeditform',
'inplaceeditform_extra_fields',
'bootstrap3_datetime',
I have tried 'django.template.loaders.eggs.Loader', both enabled and disabled.
It shows up as a clickable text, but when I click/double-click nothing happens. How do I get it to work?
Thanks,
Hec
After trying #Goin's suggestion I found that my JQuery files were not being correctly imported. had to move:
<script type="text/javascript" charset="utf-8" src="{% static 'srt/js/jquery-1.10.2.min.js' %}"></script>
<script type="text/javascript" charset="utf-8" src="{% static 'srt/js/jquery-ui.min.js' %}"></script>
to the top of my header block. Anyone working with Bootstrap, please make sure you import JQuery as the first thing in your templates.
Thanks

django-compressor creates javascript with syntax errors

A bit of background... I'm setting up my new site's base template and I'm including some popular javascript libraries, such as AngularJS, Bootstrap's javascript files, and Underscore.js. Of course I wrap these files in {% compress js %}. Example code below:
{% compress js %}
<script src="{{ STATIC_URL }}new_js/vendor/modernizr-2.6.2-respond-1.1.0.min.js"></script>
<script>window.jQuery || document.write('<script src="{{ STATIC_URL }}new_js/vendor/jquery-1.8.3.min.js"><\/script>');</script>
<script src="{{ STATIC_URL }}new_js/vendor/bootstrap.js"></script>
<!-- Angular -->
<script src="{{ STATIC_URL }}new_js/vendor/angular.min.js"></script>
<script src="{{ STATIC_URL }}new_js/angular/directives.js"></script>
<script src="{{ STATIC_URL }}new_js/angular/services.js"></script>
<script src="{{ STATIC_URL }}new_js/vendor/underscore-1.4.3.min.js"></script>
{% block extra_js %}{% endblock %}
{% endcompress %}
I know django-compressor only runs the minification filters, so it's probably the minifiers not generating the correct Javascript output.
Here is the JS error I get with JSMin:
SyntaxError: invalid increment operand
http://localhost:8000/site_media/static/cache/js/0f5eb5fb3b24.js
Line 448
And the error from the file generated by SlimIt:
SyntaxError: missing ; after for-loop initializer
http://localhost:8000/site_media/static/cache/js/7fbdf61f5abb.js
Line 1
I'm not entirely sure what's going on here, it seems hard to believe the minifiers would generate incorrect files on these common js libraries.
Has anyone run into problems with django-compressor's Javascript filters messing up common libraries?
I went on IRC and someone gave me a good tip. They told me to use the non-minified version of Javascript files. That way, you can debug in development environment. That solved most of my problems.
There was still an issue with the latest version of Underscore.js 1.4.3, but it was fixed in their dev branch.
There was also an issue with https://github.com/jonthornton/jquery-timepicker. So I just put it in {% nocompress js %} for now.

Error with static template block tag in Django 1.3

I'm trying to use the static template block tag in one of my template but I get an exception I don't understand.
Here is the template code:
<img src="{{STATIC_URL}}closed.png" alt="Closed message" />
<br/>
{% load static %}
<img src="{% get_static_prefix %}closed.png" %}" alt="Closed message"/>
<br/>
<img src="{% static "closed.png" %}" alt="Closed message"/>
The two first image display instructions work if I comment out the last one.
When the last one is uncommented I get an exception:
Invalid block tag: 'static'
The code is based on this django documentation section.
If someone is on > 1.3 and gets this issue, check your INSTALLED_APPS and make sure that 'django.contrib.staticfiles', is present. In your template include: {% load staticfiles %} and then use it as such:
//ensure the your syntax is correct
<link rel="shortcut icon" type="image/x-icon" href="{% static "assets/favicon.ico" %}?v=2" />
I ran into this problem because I had a syntax error and verified my setup as per django projects docs.
I had the same problem, and the problem turned out to be that I forgot to
{% load staticfiles %}
More about it at Django Documentation here
Are you using the development version? Most likely, you're using version 1.3, in which case you should be looking at this documentation instead.