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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T01:06:21+00:00 2026-06-18T01:06:21+00:00

I am using django-crispy-forms along with bootstrap to render my django forms. I want

  • 0

I am using django-crispy-forms along with bootstrap to render my django forms.

I want to use a file upload field like here, but I’m not sure how to get my html to output like this:

<div class="fileupload fileupload-new" data-provides="fileupload">
  <div class="fileupload-new thumbnail" style="width: 50px; height: 50px;"><img src="http://www.placehold.it/50x50/EFEFEF/AAAAAA" /></div>
  <div class="fileupload-preview fileupload-exists thumbnail" style="width: 50px; height: 50px;"></div>
  <span class="btn btn-file"><span class="fileupload-new">Select image</span><span class="fileupload-exists">Change</span><input type="file" /></span>
  <a href="#" class="btn fileupload-exists" data-dismiss="fileupload">Remove</a>
</div>

Using a ModelForm gives me an output like this:

<div id="div_id_my_id" class="control-group">
  <label class="control-label " for="id_my_id"> My Model Field</label>
  <div class="controls">
</div>

For a form like this:

class MyForm(ModelForm):
    def __init__(self, *args, **kwargs):
        super(MyForm, self).__init__(*args, **kwargs)
        self.helper = FormHelper(self)
        self.helper.layout = Layout(
            Div(
                Div('stuff', 'things' css_class='span6'),
                Div('main_image', 'my_id', css_class='span6' ),
            css_class='row-fluid'),
        )

    class Meta:
        model=MyForm

So Im going to need to add a div, a span, and change some of their attributes. Have you faced this problem? Thanks for your ideas!

  • 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-18T01:06:22+00:00Added an answer on June 18, 2026 at 1:06 am

    You can do it this way:

    from crispy_forms.layout import Field
    
    class FileField(Field):
        template = 'bootstrap/layout/file_field.html'
    
    file_field.html
    
    {% load crispy_forms_field %}
    
    <div id="div_{{ field.auto_id }}" class="control-group{% if form_show_errors%}{% if field.errors %} error{% endif %}{% endif %}{% if field.css_classes %} {{ field.css_classes }}{% endif %}">
        {% if field.label %}
            <label for="{{ field.id_for_label }}" class="control-label {% if field.field.required %}requiredField{% endif %}">
                {{ field.label|safe }}{% if field.field.required %}<span class="asteriskField">*</span>{% endif %}
            </label>
        {% endif %}
    
        <div class="controls">
            <div class="fileupload fileupload-new" data-provides="fileupload">
              <div class="fileupload-new thumbnail" style="width: 50px; height: 50px;"><img src="http://www.placehold.it/50x50/EFEFEF/AAAAAA" /></div>
              <div class="fileupload-preview fileupload-exists thumbnail" style="width: 50px; height: 50px;"></div>
              <span class="btn btn-file"><span class="fileupload-new">Select image</span><span class="fileupload-exists">Change</span><input type="file" name="{{ field.html_name }}" id="id_{{ field.html_name }}" value="{{ field.value }}" /></span>
              <a href="#" class="btn fileupload-exists" data-dismiss="fileupload">Remove</a>
            </div>
            {% include 'bootstrap/layout/help_text_and_errors.html' %}
        </div>
    </div>
    

    And then use it in your FormHelper as FileField('main_image').

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

Sidebar

Related Questions

I am using Django Crispy Forms together with Twitter-bootstrap and following this page: http://django-crispy-forms.readthedocs.org/en/d-0/tags.html#bootstrap-layout-objects
I'm using django-crispy-forms to generate a Bootstrap-compatible form. For the form submission, I have
I'm using django-crispy-forms with Twitter Bootstrap , and I'm having some issues with customizing
I'm using django ModelForm and django-crispy-forms to create beautiful bootstrap forms. I didn't find
I have started using django-cripsy-forms in a django project. I would like crispy to
I'm having difficulty using two django crispy forms simultaneously. I have one form to
I'm having a small (but annoying) problem with django forms right now. I'm using:
Am using django forms on my app. I have a model Client like this:
I am using django-registration and would like to have a different page for failed
I have the following HTML segment that I want to translate to django crispy

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.