Question: I want to do something like this:

```
app = Flask(__name__)
app.config.from_object(mypackage.config)
app.static_url_path = app.config['PREFIX']+"/static"

```

when I try:

```
print app.static_url_path

```

I get the correct `static_url_path`

But in my templates when I use `url_for('static')`, The html file generated using jinja2 still has the default static URL path `/static` with the missing `PREFIX` that I added.

If I hardcode the path like this:

```
app = Flask(__name__, static_url_path='PREFIX/static')

```

It works fine. What am I doing wrong?

Answer: 
The accepted answer is correct, but slightly incomplete. It is true that in order to change the `static_url_path` one must also update the app's `url_map` by removing the existing `Rule` for the `static` endpoint and adding a new `Rule` with the modified url path. However, one must also update the [`_rules_by_endpoint` property](https://github.com/pallets/werkzeug/blob/master/src/werkzeug/routing.py#L1502) on the `url_map`.

It is instructive to examine the [`add()` method on the underlying `Map`](https://github.com/pallets/werkzeug/blob/master/src/werkzeug/routing.py#L1555-L15655) in Werkzeug. In addition to adding a new `Rule` to its `._rules` property, the `Map` also indexes the `Rule` by adding it to `._rules_by_endpoint`. This latter mapping is what is used when you call `app.url_map.iter_rules('static')`. It is also what is used by Flask's `url_for()`.

Here is a working example of how to completely rewrite the static\_url\_path, **even if it was set in the Flask app constructor.**

```py
app = Flask(__name__, static_url_path='/some/static/path')

a_new_static_path = '/some/other/path'

# Set the static_url_path property.
app.static_url_path = a_new_static_path

# Remove the old rule from Map._rules.
for rule in app.url_map.iter_rules('static'):
    app.url_map._rules.remove(rule)  # There is probably only one.

# Remove the old rule from Map._rules_by_endpoint. In this case we can just 
# start fresh.
app.url_map._rules_by_endpoint['static'] = []  

# Add the updated rule.
app.add_url_rule(f'{a_new_static_path}/<path:filename>',
                 endpoint='static',
                 view_func=app.send_static_file)

```
I think you missed `static_folder`

```
app = Flask(__name__)
app.config.from_object(mypackage.config)
app.static_url_path = app.config['PREFIX']+"/static"
app.static_folder = app.config['PREFIX']+"/static"

```