<div class="download">
<form action="/Download/" method="post" enctype="multipart/form-data">
{% csrf_token %}
{{ form.as_p}}
<div class="button_2">
<button type="submit">Добавить</button>
</div>
</form>
</div>
def d(request):
if request.method == 'POST':
form = DownloadForm(request.POST, request.FILES)
if form.is_valid():
form.save()
return HttpResponseRedirect('/main/')
else:
return render(request, 'downloader.html', {'form': form})
else:
form = DownloadForm()
return render(request, 'downloader.html', {'form': form})
It's compatible with libjpeg API and ABI, and can be used as a drop-in replacement for libjpeg.
We include a demo cjpeg tool, but it's not intended for serious use. We encourage authors of graphics programs to use MozJPEG's C API instead.
from difflib import get_close_matches as gcm
model = 'A 170 Classic - 7/2004 - 85Kw'.upper()
model_list = map(str.upper, [
'A 170 CDI CAT ELEGANCE',
'A 170 CDI CAT CLASSIC',
'A 170 CDI CAT AVANTGARDE',
])
result = gcm(model, model_list, n=1, cutoff=0.5)[0]
print(result) # => 'A 170 CDI CAT CLASSIC'
from difflib import SequenceMatcher as SM
s1 = 'A 170 Classic - 7/2004 - 85Kw'.upper()
s2 = 'A 170 CDI CAT CLASSIC'.upper()
SM(isjunk=None, a=s1, b=s2, autojunk=True).ratio() # => 0.52
x = float('40.80')
a = int(x)
b = int(100 * (x - a))
print(a, b) # => 40 79
from decimal import Decimal
x = Decimal('40.80')
a = int(x)
b = int(100 * (x - a))
print(a, b) # => 40 80
a, b = map(int, '40.80'.split('.'))
print(a, b) # => 40 80
# python2.5 code below
# corpus is our unicode() strings collection as a list
corpus = [u"Art", u"Älg", u"Ved", u"Wasa"]
import locale
# this reads the environment and inits the right locale
locale.setlocale(locale.LC_ALL, "")
# alternatively, (but it's bad to hardcode)
# locale.setlocale(locale.LC_ALL, "sv_SE.UTF-8")
corpus.sort(cmp=locale.strcoll)
# in python2.x, locale.strxfrm is broken and does not work for unicode strings
# in python3.x however:
# corpus.sort(key=locale.strxfrm)
emps = list(Employee.objects.all())
emps.sort(key=lambda x: locale.strxfrm(x.name))