Get an absolute from a path relative to the current file

/ Published in: Python
Save to your folder(s)

Sometimes (ex. django templates section at, a function expects an absolute path, but it's more practical when developing to refer it to the current file position in our code base. The rel function does exactly that.

Copy this code and paste it in your HTML
  1. import os
  2. def rel(*x):
  3. return os.path.normcase(os.path.join(os.path.dirname(__file__), *x))

Report this snippet


RSS Icon Subscribe to comments

You need to login to post a comment.