Copy static file to absolute path

Is there a bulb function or an easy way to convert a static path to it into an absolute path to a file on disk? For example, "/static/css/style.css" needs to return the absolute path for style.css based on the static folder defined in the application or plan.

To clarify, I am currently using Flask-Asset.

{% assets "all_js" %}
    <script type="text/javascript" src="{{ ASSET_URL }}"></script>
{% endassets %}

The above section in the template will generate this on the production side. The main reason is not to use a relative path, so that I can serve statics from a cookieless domain.

<script type="text/javascript" src="/static/public/all.580e5dae.js"></script>
+4
source share
3 answers

, , , , , Flask-Assets, -.

, , Flask-Assets , .

+2
import os
base_path = os.getcwd() # Replace this appropriately with your static folder path
# We shouldn't use 'static' twice if it is already there in the base_path
# as correctly pointed out by mark-hildreth
if os.path.basename(base_path) == 'static':
    file_path = os.path.normpath('/css/style.css')
else:
    file_path = os.path.normpath('/static/css/style.css')
abs_path = os.path.join(base_path+file_path)
if os.path.exists(abs_path): # Verifies existence of given path
    print abs_path
0

easy way to solve using 'static/css/name_of_css.css'insteadurl_for('static', filename='name_of_css.css')

0
source