django-bootstrap-datepicker-plus icon indicating copy to clipboard operation
django-bootstrap-datepicker-plus copied to clipboard

AttributeError: 'list' object has no attribute 'replace'

Open MaxDragonheart opened this issue 4 years ago • 2 comments

I'm trying to use a custom form but I see this error:

File "/home/maxdragonheart/DEV_FOLDER/Django/Enographiae/enographiae_dev/devenv/lib/python3.7/site-packages/bootstrap_datepicker_plus/_base.py", line 91, in init super().init(attrs, self._calculate_format()) File "/home/maxdragonheart/DEV_FOLDER/Django/Enographiae/enographiae_dev/devenv/lib/python3.7/site-packages/bootstrap_datepicker_plus/_base.py", line 107, in _calculate_format self.config['options']['format'] = self.format_py2js(_format) File "/home/maxdragonheart/DEV_FOLDER/Django/Enographiae/enographiae_dev/devenv/lib/python3.7/site-packages/bootstrap_datepicker_plus/_base.py", line 70, in format_py2js datetime_format = datetime_format.replace(py_format, js_format) AttributeError: 'list' object has no attribute 'replace'

This happen when I add format as option of DateTimePickerInput. Below a part of my code: forms.py

    publishing_date = forms.DateTimeField(
        widget=DateTimePickerInput(
            format=['%d/%m/%Y %H:%M'],
        ),
        required=False,
    )

mytemplate.html

  <form method="POST" enctype="multipart/form-data" novalidate>
    {% csrf_token %}
    {{ form.as_p }}
    <hr>
    <div class="row justify-content-md-center">
      <div class="col-md-auto">
        <input type="submit" class="btn btn-info shadow" value="Pubblica">
      </div>
    </div>
  </form>

How I can put date and time as dd/mm/yyy hh:mm precisely?

MaxDragonheart avatar Apr 25 '20 08:04 MaxDragonheart

The problem is you are passing a list as format argument. You should pass a single format string.

format='%d/%m/%Y %H:%M'

monim67 avatar May 02 '20 09:05 monim67

Thank you! This problem is solved but now I have another problem. I can't change date and time. If I change date and time the post is published only with today date and time.

MaxDragonheart avatar May 03 '20 15:05 MaxDragonheart

Closing pre v5 issues as stale.

monim67 avatar Nov 25 '22 17:11 monim67