[Solved] PyCharm Start Error: TypeError: unsupported operand type(s) for /: ‘str’ and ‘str’

This prompt probably says: “Type error: The operation type is not supported as string and string”, directly put the two strings (BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__ ))) It is improper to connect in the list as the basic path, that is, the path of the entire project. Here the system understands “/” as a division sign, and the system understands it as “string/string”. In fact, what I want to express here is to concatenate BASE_DIR and’templates’ together to form a complete path, and “/” is the path separator.

Solution: change the settings.py'DIRS': [BASE_DIR / 'templates'] 修改为 'DIRS': [str.format(BASE_DIR,'/templates']

Or’DIRS’: [(‘%s/templates’)% BASE_DIR]

Or’DIRS’: [os.path.join(BASE_DIR,’templates’)]  can also be solved

Similar Posts:

Leave a Reply

Your email address will not be published. Required fields are marked *