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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T04:35:27+00:00 2026-05-23T04:35:27+00:00

I want to add some html element (button, a tag, etc ) to a

  • 0

I want to add some html element (button, “a” tag, etc ) to a django admin page. How can i do it? Please help.

  • 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-05-23T04:35:28+00:00Added an answer on May 23, 2026 at 4:35 am

    Not sure where you want to add your stuff but this is a solution I found somewhere else on SO to change the HTML of a FileField (in my case i wanted to display the current image in an ImageField).

    In other words you can make a widget that modifies the html of the field you want to customize:

    # Widget that modifies the output of a FileField
    class OutputWidget(AdminFileWidget):
        # Overloaded django magic
        def render(self, name, value, attrs=None):
            output = []
            # This is the place where we edit the output    
            if value and getattr(value, "url", None):
                image_url = value.url
                output.append(u' <a href="%s" target="_blank"><img src="%s" alt="%s" /></a>' % (image_url, image_url, image_url))
            output.append(super(AdminFileWidget, self).render(name, value, attrs))
            return mark_safe(u''.join(output))
    
    # ModelAdmin class that is applied to the model
    class MyModelSettings(admin.ModelAdmin):
        # Overloaded django magic
        def formfield_for_dbfield(self, db_field, **kwargs):
            # Look for the field we want to edit and register the widget with it
            if db_field.name == 'nameOfFieldIWantToEdit':
                request = kwargs.pop("request", None)
                kwargs['widget'] = OutputWidget
                return db_field.formfield(**kwargs)
            return super(MyModelSettings,self).formfield_for_dbfield(db_field, **kwargs)
    
    # Register my overloaded settings with the model
    admin.site.register(MyModel, MyModelSettings)
    

    The code goes into admin.py where you register your models.

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

Sidebar

Related Questions

I'm developing a web page using django and I want to add some javascript
I want to add some Ajax -niceness to my Django-coded website. In my Django
In this page there's a way to dynamic add html (textbox,input button and radio
I want to add some logging capability to a cf.net application running on WM6
I have a view that I want to add some custom drawing to. I
Suppose I have some application A with a database. Now I want to add
I want to add a mailto link on our web page. I want to
I have an <input> field in my web page, and I want to add
I want to add HTML like this: <div><img src=item.png/>&nbsp;<a href=#><span>Hello</span></a></div> but in some cases
I want to add a comment to some elements in a Flex document, and

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.