protibimbok / django-vite-plugin

This plugin configures Vite for use with Django backend.
103 stars 13 forks source link

TypeError: unsupported operand type(s) for /: 'str' and 'str' #43

Closed delbronski closed 10 months ago

delbronski commented 11 months ago

Hey, cool project. But could not get it to work in python v3.11.6. I get the following error:

TypeError: unsupported operand type(s) for /: 'str' and 'str'

Seems like in a few places you are using this kind of syntax:

getattr(settings, 'BASE_DIR') / 'static' and python thinks you are trying to divide strings.

protibimbok commented 11 months ago

How can I re-create this error?

jbuerklin commented 10 months ago

@delbronski the problem might be that you're using an outdated version of Django.
Django 3.1 changed the way how BASE_DIR is defined.
Prior to 3.1 it was a string, defined as

import os
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

Recent versions implement it as

from pathlib import Path
BASE_DIR = Path(__file__).resolve(strict=True).parent.parent

with the advantage that pathlib.Path objects can be concatenated using /, as in your example: BASE_DIR / 'static' instead of os.path.join(BASE_DIR, 'static')