externally hosted static files

35 views
Skip to first unread message

Matt Bodman

unread,
Jul 20, 2020, 10:10:58 PM7/20/20
to pylons-discuss
Hi, I need help troubleshooting something.  I currently host my static files within my Pyramid repo, but I want to add more files and host them on S3.  I have tried just about every permutation of the static view config I can think of, but just can't get it to work.

If the sub url is `/static` and the files are hosted at `http://bla.s3`, what do I pass the `add_static_view` method?

Any clues would be appreciated!

Steve Piercy

unread,
Jul 21, 2020, 9:51:20 AM7/21/20
to pylons-...@googlegroups.com
add_static_view accepts a fully-qualified URL as the first argument.

https://docs.pylonsproject.org/projects/pyramid/en/latest/api/config.html#pyramid.config.Configurator.add_static_view

However for files that are not in your repo/package, I would suggest you not use add_static_view. Instead create an external route to generate URLs that you add into your templates.

https://docs.pylonsproject.org/projects/pyramid/en/latest/narr/urldispatch.html#external-routes

This is a kind of hand-wavy suggestion. I'm sure someone else who uses a CDN in their app has more details or a better technique.

--steve
> --
> You received this message because you are subscribed to the Google Groups "pylons-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to pylons-discus...@googlegroups.com <mailto:pylons-discus...@googlegroups.com>.
> To view this discussion on the web visit https://groups.google.com/d/msgid/pylons-discuss/a8c48aa8-871e-4aa8-bd39-86762ec2a748n%40googlegroups.com <https://groups.google.com/d/msgid/pylons-discuss/a8c48aa8-871e-4aa8-bd39-86762ec2a748n%40googlegroups.com?utm_medium=email&utm_source=footer>.

Matt Bodman

unread,
Jul 21, 2020, 7:30:00 PM7/21/20
to pylons-...@googlegroups.com
Thanks Steve, hadn't thought of that.  I'll take your hand-wavy suggestion and do some half-arsed testing.

You received this message because you are subscribed to a topic in the Google Groups "pylons-discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/pylons-discuss/LEWEDhPF7gk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to pylons-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pylons-discuss/b3ff6472-4057-1337-5273-d4f01d53d503%40gmail.com.


--
Matt Bodman

ACCTV

Share your testimony about ACCTV with us. Head to acc.tv/testimonials

Ph +61 7 5478 1399
Mob +61 421 582 240


Jonathan Vanasco

unread,
Jul 23, 2020, 5:17:56 PM7/23/20
to pylons-discuss
This is a very simplified version of my approach:

I typically handle this by injecting a `cdn` variable into the default rendering environment, and then just having the templates reference 

    href="${cdn}/path/to/file"

I specify the `cdn` var in the `.ini` file for the application. on startup, i load it into the registry and a few other places.

On some projects, I have routine that preprocesses the templates for a handful of "global" variables.
Reply all
Reply to author
Forward
0 new messages