0

I have my development server ( django 1.5 ). In this server i can create javascript templates without problem.

The empty view just returns a template. Now, in this template i have the following code:

{% load verbatim %}
<!DOCTYPE html>
<html>

<head>
<link href="http://0.0.0.0:8080/css/bootstrap/2.3.1/css/bootstrap.css" rel="stylesheet" type="text/css" />
<link href="http://0.0.0.0:8080/css/bootstrap/2.3.1/css/bootstrap-responsive.css" rel="stylesheet" type="text/css" />


</head>
<body>
    <div class="container-fluid">
        <div class="row-fluid">
            <div class="span12">
                <div id="result"></div>
            </div>
        </div>
    </div>

    <!-- The javascript template -->
    <script src="http://blueimp.github.io/JavaScript-Templates/js/tmpl.min.js"></script>
    {% verbatim %}
    <script type="text/x-tmpl" id="tmpl-demo" src="">
        <h3>{%=o.title%}</h3>
        <p>Released under the
        <a href="{%=o.license.url%}">{%=o.license.name%}</a>.</p>
        <h4>Features</h4>
        <ul>
        {% for (var i=0; i<o.features.length; i++) { %}
            <li>{%=o.features[i]%}</li>
        {% } %}
        </ul>
    </script>
    {% endverbatim %}


    <!-- The javascript -->
    <script type="text/javascript">
        var data = {
                "title": "JavaScript Templates",
                "license": {
                    "name": "MIT license",
                    "url": "http://www.opensource.org/licenses/MIT"
                },
                "features": [
                    "lightweight & fast",
                    "powerful",
                    "zero dependencies"
                ]
            };

            document.getElementById("result").innerHTML = tmpl("tmpl-demo", data);
    </script>
    </body>
</html>

For the record: The tag {% verbatim %} is used so django template engine ignores the template script as they both use a very similar syntax

Now, when i try running the same same page in the main server, which is using apache and django 1.4.5, the template script seems not to be recognized. In firebug i get the following error: SyntaxError: unexpected garbage after function body, starting with '}'

If i remove all the javascript template tags inside the text/x-tmpl script, then no error is displayed.

This leads me to think that the browser thinks that the text/x-tmpl is javascript because:

  • I am missing to send something in the view
  • Something missing in my apache configuration

I tried to search around, but i couldnt find anything.

Does any of you have idea how to fix this?

Thanks :)

Edit 1: This is the link to the javascript templates wiki https://github.com/blueimp/JavaScript-Templates

Edit 2: This is the django view

@login_required
def test(request):
    return render_to_response('myapp/test.html', locals(), context_instance = RequestContext(request))
6
  • How you are rendering template? Can you post view ? Commented Jun 15, 2015 at 10:26
  • 1
    Why are you doing {% load verbatim %}? Commented Jun 15, 2015 at 10:30
  • itzmeontv: Jus added the view :) Mevius: In django, you need to load custom template tags like that before you can use them Commented Jun 15, 2015 at 10:33
  • 1
    The verbatim tag wasn't added until Django 1.5. Have you backported it to Django 1.4? Commented Jun 15, 2015 at 10:43
  • to use verbatim, there is no need of {% load verbatim %} Commented Jun 15, 2015 at 10:50

2 Answers 2

1

First of all, thank you all for your help :)

I had made previously a custom verbatim template tag to use for django 1.4, and as Alasdair pointed out, a default verbatim tag was added to django 1.5... something which i never noticed.

With that being said, in my development server (which is running django 1.5) was using the django verbatim template tag... while the other server (which is running django 1.4) was using my custom template tag.

About the firebug error. It was thrown because of wrong spacing between tokens.

Django 1.5 verbatim tag would render {% } %} and my custom template tag would render {%}%}.

So i just added the correct spacing in my custom template tag and problem was solved.

Sign up to request clarification or add additional context in comments.

Comments

0

If you are trying to use verbatim, just use

{% verbatim %}
    #Your codes which may affect django template syntax
{% endverbatim %}

No need of {% load verbatim %}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.