1

In my base.html, I currently have two lines to handle both a local (debugging) serving and the remote (production) serving. This is to make sure that one of locations are served. For instance:

<link rel="stylesheet" type="text/css" href="/static/jquery.dataTables.min.css">
<link rel="stylesheet" type="text/css" href="/otherroot/static/jquery.dataTables.min.css">

This is of course silly and I am looking for a better solution so I do not get a 404 each time.

I was hoping app.config["APPLICATION_ROOT"] could help as in Add a prefix to all Flask routes and in the two app.py files with create_app and app.run() I have set the app.config["APPLICATION_ROOT"] to either '/' and '/otherroot/'.

I have also tried send_from_directory from How to serve static files in Flask but that neither seems to work.

Update

The first part of base.html reads

{% extends "bootstrap/base.html" %}

{% block head %}
{{super()}}

<link rel="stylesheet" type="text/css" href="/static/jquery.dataTables.min.css">
<link rel="stylesheet" type="text/css" href="/otherroot/static/jquery.dataTables.min.css">
...

Note that the application is also using StaticCDN which complicate things.

Finn Årup Nielsen
  • 6,130
  • 1
  • 33
  • 43
  • Is `base.html` a static file or a template? If a template, could you include the code that's rendering it? – Luis Orduz Jun 13 '17 at 18:19
  • `base.html` is a template that other templates extends from. I have added the first part of that file. – Finn Årup Nielsen Jun 13 '17 at 18:27
  • Can't you pass `APPLICATION ROOT` as a parameter to the template and modify the links into `href="{{ application_root }}/static/.."`? – Luis Orduz Jun 13 '17 at 18:33
  • I suppose I could. But that would mean that I have to modify all the views to add this extra parameter with something like: `return render_template('index.html', application_root=current_app.config['APPLICATION_ROOT'])` – Finn Årup Nielsen Jun 13 '17 at 19:08
  • I have implemented patterns similar to `` as suggested in https://stackoverflow.com/questions/16351826/link-to-flask-static-files-with-url-for and it seems to work on both servers. – Finn Årup Nielsen Jun 13 '17 at 20:04

0 Answers0