These are chat archives for django/django

22nd
Jul 2015
inlanger
@inlanger
Jul 22 2015 12:36
Could anybody tell me how I can get local currency code or name based on user's location?
Mir Nazim
@mnazim
Jul 22 2015 12:42
@inlanger GeoNames data countains currency data too http://www.geonames.org/countries/
inlanger
@inlanger
Jul 22 2015 12:45
Looks like they have a python library https://github.com/geopy/geopy
Krishna Regmi
@kisna72
Jul 22 2015 16:41
A quick question that I can't seem to find answers to anywhere else.
I am using django forms.
and I want to use Bootstrap in my html.
so my template looks like this :
{% for field in form %}
    <div class="form-group">
        {{ field.label_tag }}<!--Same thing as : <label for="{{field.id_for_label}}"></label> -->

        <input type="{{field.type}}" class="form-control" id="{{field.auto_id}}" placeholder="Email">
      </div>
    {% endfor %}
What I can't seem to figure out is how to get the type value.
Instead of writing out the field like
{{field}}
I want to be able to use : <input type="{{field.type}}" class="form-control" id="{{field.auto_id}}" placeholder="Email">
<form action="/" method="post" enctype="multipart/form-data" >
    {% csrf_token %}
    {% for field in form %}
    <div class="form-group">
        {{ field.label_tag }}

        <input type="{{field.type}}" class="form-control" id="{{field.auto_id}}" placeholder="Email">
      </div>
    {% endfor %}
    <p><input type="submit" value="Submit" /></p>
    </form>
Krishna Regmi
@kisna72
Jul 22 2015 16:47
I didn't find anything about it in the docs. Which is weird because this seems like the simplest thing.
Mir Nazim
@mnazim
Jul 22 2015 16:51
@kisna72 try field.field.type
Krishna Regmi
@kisna72
Jul 22 2015 16:53

@mnazim using

    <input type="{{field.field.type}}" class="form-control" id="{{field.auto_id}}" placeholder="">

produces

    <input type="" class="form-control" id="id_width" placeholder="">
Any other suggestions?
Mir Nazim
@mnazim
Jul 22 2015 17:02
@kisna72 Sorry. It's field.widget.input_type. My bad.
Krishna Regmi
@kisna72
Jul 22 2015 18:56
Hey @mnazim that didn't work either. I have create a stackoverflow question here : http://stackoverflow.com/questions/31569563/get-the-type-of-field-in-django-template