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

  • SEARCH
  • Home
  • 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 7996483
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T14:43:10+00:00 2026-06-04T14:43:10+00:00

I have accented characters in my settings.py that I access in a view using

  • 0

I have accented characters in my settings.py that I access in a view using getattr(settings, ‘MY_CONSTANT_NAME’, []) but the getattr() call return broken characters (for example, “ô” become: “\xc3\xb4”).

here is the code in view.py:

    from django.conf import settings

    def getValueFromSetting(request):
        mimetype = 'application/json' 
        charset=utf-8' datasources = getattr(settings, 'MY_CONSTANT_NAME', []) 
        config= '{' 
        config+= '"datasources": ' + str(datasources).replace("'", '"') 
        config+= '}'

        return HttpResponse(config,mimetype)                      

What I have done so far to try to solve the problem:

  • I put # –– coding: utf-8 –– as the first line of my settings.py and my views.py
  • I put u’ô’ or unicode(‘ô’) in front of special characters in settings.py
  • I put DEFAULT_CHARSET = ‘utf-8’ in settings.py
  • I try all possible combination of .decode(‘utf-8’), .encode(‘utf-8’), .decode(‘iso-8859-1’), .encode(‘iso-8859-1’) on the special characters in settings.py or in the views.py…

Nothing solve the problem.

Any suggestion to solve this problem?

Thank you

Etienne

  • 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-04T14:43:13+00:00Added an answer on June 4, 2026 at 2:43 pm

    I assume you’re seeing these \xc3\xb4 strings in your browser.. Have you tried editing your template file to define the proper charset in the HTML header?

    <head>
      <meta name="description" content="example" />
      <meta name="keywords" content="something" />
      <meta name="author" content="Etienne" />
      <meta charset="UTF-8" />      <!--  <---- This line -->
    </head>
    

    Edit after your first comment in this answer:

    I suspect getattr will not work with other than ascii encoding. Do you think something like the following will not do what you want?

    from django.conf import settings
    
    def getValueFromSetting(request):
        myConstantValue = settings.MY_CONSTANT_NAME
        # check myConstantValue here
    

    Edit after last comments:

    I think now I understand your problem. You don’t like the fact that the JSON returned by the view is ASCII-only. I recommend you to use dumps function provided by the json module bundled with Python. Here’s an example:

    # -*- coding: utf-8 -*-
    # other required imports here
    import json
    
    def dumpjson(request):
       response = HttpResponse(json.dumps(settings.CONSTANT_TUPLE, encoding='utf-8', ensure_ascii=False), content_type='application/json')
    
       return response
    

    The CONSTANT_TUPLE in the example is just a copy of DATABASES in my settings.py.

    The important bit here is ensure_ascii=False. Could you try it? Is that what you want?

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

Sidebar

Related Questions

Say that you have a XHTML document in English but it has accented characters
Quest I am looking to fetch rows that have accented characters. The encoding for
I have a HTML form that is sometimes submitted with accented characters: à, è,
I have some data with messed-up accented characters. For example in the data we
I have a database table that contains names with accented characters. Like ä and
I have a webapp that stores French text -- which potentially includes accented characters
I have a webpage that outputs a string that contains accented characters. I have
I have a problem with sending mails that preserve accented characters. By reading some
I have an array I'm trying to asort using php. The problem is that
I have an ASP Access database that contains strings in various European languages. The

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.