Python Daily
2.57K subscribers
1.48K photos
53 videos
2 files
38.9K links
Daily Python News
Question, Tips and Tricks, Best Practices on Python Programming Language
Find more reddit channels over at @r_channels
Download Telegram
Creating a webp image on post_save

Hi everyone,

I've figured out how to create a webp image in my /media/ folder within the correct directory. Now, I'm needing to save this image to a field that i've crated on my model.

def create_webp_image(sender, instance, *args, **kwargs):

image_url = instance.image.thumbnail['1920x1080'].url

path = "http://localhost:8000" + image_url
response = requests.get(path, stream=True)

img = Image.open(BytesIO(response.content))

#build filepath
position = path.rfind("/") + 1
newpath2 = path[0:position].split('/media/')[1]

#get name of file (eg. picture.webp)
name_of_file = path[position:].split('.')[0] + ".webp"

#get directory
image_dir = os.path.join(settings.MEDIA_ROOT, '')


/r/django
https://redd.it/1005ij1
PSA: You should remove "wheel" from your build-system.requires

A lot of people have a pyproject.toml file that includes a section that looks like this:

build-system
requires = "setuptools", "wheel"
build-backend = "setuptools.buildmeta"

setuptools is providing the
build backend, and wheel used to be a dependency of setuptools, in particular wheel used to maintain something called "bdistwheel".

This logic was moved out of wheel and into setuptools in v70.1.0, and any other dependency that setuptools has on wheel it does by vendoring (copying the code directly).

However, setuptools still uses wheel if it is installed beside it, which can cause failures if you have an old setuptools but a new wheel. You can solve this by removing wheel, which is an unnecessary install now.

If you are a public application or a library I would recommend you use setuptools like this:

build-system
requires = "setuptools >= 77.0.3"
build-backend = "setuptools.buildmeta"

If you are a non-public application I would recommend pinning setuptools to some major version, e.g.

[
build-system]
requires = ["setuptools ~= 77.0"]
build-backend = "setuptools.buildmeta"

Also, if you would like a more simple more stable build backend than setuptools check out flit: https://github.com/pypa/flit

If flit isn't feature rich enough for you try hatchling: https://hatch.pypa.io/latest/config/build/#build-system

/r/Python
https://redd.it/1jwbymm