Daily Notes: RWiR - Search Combo
SO: Django - form not validating
I posted this yesterday, however, no one answered me on SO. So I experimented a bit and searched for a while online, finally I figured it out… Most of the seemingly unsolvable mystery caused by the holes in the knowledge. Luckily, they can be patched:
- apparently, you need to bind uploaded images to a form, that is:
- adding
enctype="multipart/form-data"
in theform
tag - when you use the form, you need to bind the file data.
- adding
- use
request.FILES
as well asrequest.POST
inviews.py
working out the logic
SO: Bootstrap 4 - table -column sizing
<thead>
<tr>
<th class="w-25">25</th>
<th class="w-50">50</th>
<th class="w-25">25</th>
</tr>
</thead>
or
<table class="table table-bordered">
<thead>
<tr class="d-flex">
<th class="col-3">25%</th>
<th class="col-3">25%</th>
<th class="col-6">50%</th>
</tr>
</thead>
<tbody>
<tr class="d-flex">
<td class="col-sm-3">..</td>
<td class="col-sm-3">..</td>
<td class="col-sm-6">..</td>
</tr>
</tbody>
</table>
Django - build_absolute_uri, official doc
>>> request.build_absolute_uri()
'https://example.com/music/bands/the_beatles/?print=true'
>>> request.build_absolute_uri('/bands/')
'https://example.com/bands/'
>>> request.build_absolute_uri('https://example2.com/bands/')
'https://example2.com/bands/'
DetailView kwarg setting
if you wish not use pk
as the default queryset kwarg, you can change it by defining pk_url_kwarg = 'ref'
in the view.
*args and **kwargs
*args
and**kwargs
can represent a number of arguments when defining a function- they can also be used to call a function requires positional parameters
SO: prevent repeat form submission
Easy fix on client side: onclick="this.disabled=true,this.form.submit();"
attribute added on submit button, however, server side should be double prove as well… check the post