AttributeError: 'WindowsPath' object has no attribute 'rpartition' when setting directory

Question:

After typing

STATIC_ROOT = BASE_DIR / "staticfiles"

in settings.py I get the error in the tittle.

I tried with STATICDIR but it still doesn’t work. I am pretty new to django so I don’t really know other ways to fix it.

EDIT: turns out I tried to install the template folder in the INSTALLED APPs thingy

Asked By: naskoto

||

Answers:

Simply you can try following way:

STATIC_URL = '/static/'

STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static')]

And in your template, load the static using following tag:

{% load static %}
Answered By: Manoj Tolagekar

STATIC_ROOT (and all other path-related options) must be a string, not a Path.

Cast it in the assignment:

STATIC_ROOT = str(BASE_DIR / "staticfiles")
Answered By: AKX
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.