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 8483151
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T20:00:53+00:00 2026-06-10T20:00:53+00:00

I have a bunch of unicode strings in my data which I need to

  • 0

I have a bunch of unicode strings in my data which I need to pass from my django view to template for using in a JavaScript scriptlet that passes it to the web back and forth.

The problem is I want the strings to be represented in the JavaScript unicode form but I get strings with a u prefix from python.

For example, for the string mężczyźni, Python stores it as u’m\u0119\u017cczy\u017ani’ but when it is passed to the template, it does not remove the u prefix which creates problems for JavaScript while processing it. I want it to be simply ‘m\u0119\u017cczy\u017ani’ so that the JavaScript code in the template can use it.

I tried using urqluote, smart_unicode, force_unicode but couldn’t hit a solution or even a hack.

What do I do ?

  • 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-10T20:00:54+00:00Added an answer on June 10, 2026 at 8:00 pm

    Edit: Django 1.7+ no longer includes simplejson. Instead of

    from django.utils import simplejson
    

    write

    import json
    

    and then use json instead of simplejson.


    You are probably printing the python repr of your data dict, and trying to parse it in javascript:

    {{ your_python_data }}
    

    Instead, you could export your data in json:

    from django.utils import simplejson
    
    json_data_string = simplejson.dumps(your_data)
    

    And load the data directly in javascript:

    var your_data = {{ json_data_string }};
    

    You could also make a template filter:

    from django.utils import simplejson
    from django import template
    from django.utils.safestring import mark_safe
    
    register = template.Library()
    
    
    @register.filter
    def as_json(data):
        return mark_safe(simplejson.dumps(data))
    

    And in your template:

    {% load your_template_tags %}
    
    {{ your_python_data|as_json }}
    

    Note that you should be careful with XSS, if some of “data” comes from user input, then you should sanitize it.

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

Sidebar

Related Questions

I have bunch of strings, some of which are fairly long, like so: movie.titles
I have bunch of temporal data which I want to convert to RDF format.
I have bunch of methods in which i need to test whether remote server
I have a bunch of NVARCHAR columns which I suspect contain perfectly storable data
I have bunch pages and I need to validate data there. If culture for
We have bunch of Domain Entities which should be rendered to an html format,
I have a bunch of files in a folder checked out from a repository.
I have a bunch of strings that are dependent on static dictionaries and each
I have bunch of web document and want to remove the html tags from
I'm working on a project which needs to be Unicode aware. PHP provides bunch

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.