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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T05:37:58+00:00 2026-06-05T05:37:58+00:00

I have a drop down box on my Django form that contains the ®

  • 0

I have a drop down box on my Django form that contains the ® HTML entity. Is there an easy way to get Django to mark it as safe?

This doesn’t work:

{{ form.myoptions.label_tag }}
{{ form.myoptions|safe }}

Edit:

I should mention that the drop down box is generated from a ForeignKey field.

  • 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-05T05:37:59+00:00Added an answer on June 5, 2026 at 5:37 am

    You’re right – it doesn’t work… I suppose the easiest way is to mark it safe from python.

    from django.utils.safestring import mark_safe
    
    MY_CHOICES = [
        ('foo', mark_safe('& foo')),
        ('bar', 'bar'),
    ]
    

    According to the source it looks like you can either define a ModelChoiceField.choices manually or write a new field and override label_from_instance.

    class MyModelForm(forms.ModelForm):
        class Meta:
            model = Foo
        def __init__(self, *args, **kwargs):
            super(MyModelForm, self).__init__(*args, **kwargs)
            self.fields['foo'].choices = ((foo.id, mark_safe(foo.bar)) for foo in Foo.objects.all())
    
    
    
    class SafeModelChoiceField(ModelChoiceField):
        def label_from_instance(self, obj): 
            return mark_safe(obj)
    

    I think I prefer constructing the choices myself so that any other magical ModelForm field -> form field conversion isn’t overwritten.

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

Sidebar

Related Questions

I have a drop-down box in my VB6 form, I was wondering if there
I have a drop down box that contains a list of names and a
I want to have a drop down box that has a list of different
I have a drop down box next to html link tag element, the link
I currently have a drop-down menu box that takes an element from a column
I have a case where I have a drop-down box in an HTML webpage
I have a drop down box that populates textbox values based on its value.
Hey, I have a drop down box done in html and I'm just wondering
I have a list of Payees in a drop down box on my form.
I have an html table of data with a drop down box in each

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.