Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7808647
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T03:11:39+00:00 2026-06-02T03:11:39+00:00

How can I use Django’s template tags within JavaScript? This is my code: {%

  • 0

How can I use Django’s template tags within JavaScript? This is my code:

{% block scripts %}
<script>
    $(document).ready(function() {
        var classEditor = {
            dcg: $("div.control-group"),

            set: function(i, errors) {
                $dcg = $(classEditor.dcg[i]);
                $dcg.addClass("error");
                $dcg.children('div').children('div').children('p').text(errors);
            }
        };

        {% if form.email.errors %}
            {% for err in form.email.errors %}
                {{ e|add:err }}
            {% endfor %}
            classEditor.set(1, {{ e }});
        {% endif %}
    })
</script>
{% endblock %}

I want to send all errors to a function and do something with it. I tried to use striptags and stringformat, but it always raises errors.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T03:11:41+00:00Added an answer on June 2, 2026 at 3:11 am

    I don’t think your problem has to anything to do with Javascript. The issue is here:

    {{ e|add:err }}
    

    This makes no sense at all. It seems like you’re trying to build up a list, e, consisting of all the items in form.email.errors. But you can’t do that sort of thing in a template – no data manipulation is allowed, by design. The add filter simply performs numeric calculations for display, it doesn’t modify objects.

    You probably want to serialize the errors to JSON in your view, and pass that JSON object to classEditor.set.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm looking for something I can use within django to display preformatted code. Ideally
In Django's template language, you can use {% url [viewname] [args] %} to generate
I am using Memcache for my Django application. In Django, developers can use template
In smarty templates you can use raw PHP code in a template by placing
As we all know (or should), you can use Django's template system to render
Filtering QuerySets in Django work like the following: Entry.objects.filter(year=2006) How can I use filter
The Django admin site makes use of a really cool widget: How can I
The default widget for ManyToManyFields in django-admin is difficult to use. I can set
I can use vi{ and va{ to select C++ code blocks. It helps me
Does anyone know how you can use Django's templatetags in view? I want to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.