os.path.join - how to cope with absolute path
<p><strong>Python 3.5.2</strong></p>

<pre><code>BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
STATIC_URL = '/static/'
</code></pre>

<p>I want to join them:</p>

<pre><code>STATIC_ROOT = os.path.join(PROJECT_PATH, STATIC_URL)
</code></pre>

<p>The result is '/static/'.  </p>

<p>This is the documentation:
<a href="https://docs.python.org/3/library/os.path.html" rel="nofollow">https://docs.python.org/3/library/os.path.html</a></p>

<p>We can read that "If a component is an absolute path, all previous components are thrown away and joining continues from the absolute path component."</p>

<p>In my case BASE_DIR in the debugger is '/home/michael/PycharmProjects/photoarchive/photoarchive'.</p>

<p>Well, this is an absolute path. Well, it eve was acquired via abspath function.</p>

<p>So, there first component - BASE_DIR - is an absolute path. </p>

<p><strong>Could you tell me why it is thrown away? 
And how to get '/home/michael/PycharmProjects/photoarchive/photoarchive/static'?</strong></p>

<p>"If a component is an absolute path, all previous components are thrown away and joining continues from the absolute path component." applies here: <code>STATIC_URL</code> is an absolute path because it starts with <code>/</code>, so <code>BASE_DIR</code> is dropped.</p>

<p>Drop the leading <code>/</code> else dirname thinks that <code>STATIC_URL</code> is absolute and keeps only that.</p>

<pre><code>BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
STATIC_URL = 'static/'
</code></pre>

python