question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support URLs that don't start with `/static/`

See original GitHub issue

In template_tags.py#L19 a TODO says exactly that.

I’d like to tackle this one, as we need it in one of our projects.

Do you have any hints on how to do this? Introduce a config setting, and if present use that as a base url for static assets? Did you have any concrete plans/ideas on how to implement this?

I wonder if it would be a good idea to reuse django’s STATIC_ROOT related capabilities (or rather the collectstatic contrib to be exact) for that.

But this would somehow contradict the item on the roadmap (see #117) which states/asks, that other template engines than Django’s would be a nice feature.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:7

github_iconTop GitHub Comments

1reaction
benjmin-rcommented, Aug 1, 2016

We went the route of implementing a simple plugin, that reads an optional config.json file and given that file contains a key named static_base_url sets the template variable STATIC_URL to the respective value.
This also allowed us to maintain most of our cactus v2 templates unchanged.

The following is the plugin code, which you are free to use as is.

import os
from cactus import config

INFO = {
    'name': 'CUSTOM_STATIC_URL',
    'description': 'Set STATIC_URL to value from config.json in project dir'
}

STATIC_URL_KEY = 'static_base_url'
conf = config.Config('config.json')

def preBuildPage(site, path, context, data):
    if conf.get(STATIC_URL_KEY):
        context.update({ 'STATIC_URL': conf.get(STATIC_URL_KEY) })
    else:
        context.update({ 'STATIC_URL': '/static' })
    return context, data

… and a sample config.json

{
    "static_base_url": "https://cdn.example.com/somepath"
}

I’ll close this issue, as I’ll not put any further work into it. Sorry, for keeping it open for so long, without any update.

0reactions
maceddcommented, Oct 9, 2016

The plugin does not work with the {% static %} tamplate tag

Read more comments on GitHub >

github_iconTop Results From Across the Web

Dynamic URLs vs. static URLs | Google Search Central Blog
A static URL is one that does not change, so it typically does not contain any URL parameters. It can look like this:...
Read more >
Why You Should Avoid Dynamic URLs - codeburst
Static URLs do not accept string parameters and are not dynamically generated. This means that the only way to modify the content of...
Read more >
When to use static urls and when dynamic urls [closed]
I want my web-site to be SEO-ed and for which I will be using static URLs (RESTful web services). But in some scenarios,...
Read more >
Dynamic URLs vs. Static URLs - The Best Practice for SEO is ...
Providing search engines with dynamic URLs should be favored over hiding parameters to make them look static. The fundamental problem here is ...
Read more >
The Complete Guide on Structuring Your URLs Correctly
Dynamic URLs change and include parameters. Static URLs stay the same as long as no changes are made within the HTML. They are...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found