0

I just wanted to understand something about adding a templates folder in django. This is the code for including my templates folder, that django conveniently made for me:

TEMPLATE_DIRS = (
    # This includes the templates folder
    os.path.join(os.path.dirname(__file__), '..', 'templates').replace('\\','/'),
)

What I do not understand is the part with 'templates', why is it not '/templates', or even \\templates in the case of something Unix based? I come here after reading this article, in particular the part about Template Loading.

1 Answer 1

2

os.path.join is building the absolute path based on the operating system being used.

Here, Django is computing the templates directory by getting the path. Here, windows would have included a \\, hence the .replace

You can read more about it here

Sign up to request clarification or add additional context in comments.

2 Comments

So, its pretty much the same path that I would just type into cmd?
Pretty much - yes. Just that an inbuilt python library is being used for the join

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.