static-files

How to serve static files in Flask

无人久伴 提交于 2020-08-20 14:57:12
问题 So this is embarrassing. I've got an application that I threw together in Flask and for now it is just serving up a single static HTML page with some links to CSS and JS. And I can't find where in the documentation Flask describes returning static files. Yes, I could use render_template but I know the data is not templatized. I'd have thought send_file or url_for was the right thing, but I could not get those to work. In the meantime, I am opening the files, reading content, and rigging up a

How to serve static files in Flask

独自空忆成欢 提交于 2020-08-20 14:56:10
问题 So this is embarrassing. I've got an application that I threw together in Flask and for now it is just serving up a single static HTML page with some links to CSS and JS. And I can't find where in the documentation Flask describes returning static files. Yes, I could use render_template but I know the data is not templatized. I'd have thought send_file or url_for was the right thing, but I could not get those to work. In the meantime, I am opening the files, reading content, and rigging up a

How to configure CORS policy in Cloud Foundry Staticfile Buildpack to add missing 'Access-Control-Allow-Origin' header

喜你入骨 提交于 2020-06-17 04:31:09
问题 When I try to access a JavaScript file hosted on Cloud Foundry using the Staticfile Buildpack, my browser refuses to load it and displays an error message in the console: Access to script at ‘…’ from origin ‘…’ has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource How do I configure cross-origin resource sharing (CORS) in the Cloud Foundry Staticfile Buildpack? 回答1: To set up CORS with the Staticfile Buildpack: Create a file named

Where to run collectstatic when deploying django app to heroku using docker?

≡放荡痞女 提交于 2020-06-16 15:43:07
问题 I am deploying a Django app to Heroku using Docker. When I put RUN manage.py collectstatic --noinput in the Dockerfile, it fails because there is no value set for the environment variable DJANGO_SECRET_KEY . My understanding is that this is because config vars aren't available during build time. When I run collectstatic as a release command, it works without error, and successfully copies the static files. However, when I hit the app url, it returns a 500 error because the static files can't

Where to run collectstatic when deploying django app to heroku using docker?

别来无恙 提交于 2020-06-16 15:42:51
问题 I am deploying a Django app to Heroku using Docker. When I put RUN manage.py collectstatic --noinput in the Dockerfile, it fails because there is no value set for the environment variable DJANGO_SECRET_KEY . My understanding is that this is because config vars aren't available during build time. When I run collectstatic as a release command, it works without error, and successfully copies the static files. However, when I hit the app url, it returns a 500 error because the static files can't

Where to run collectstatic when deploying django app to heroku using docker?

人走茶凉 提交于 2020-06-16 15:41:47
问题 I am deploying a Django app to Heroku using Docker. When I put RUN manage.py collectstatic --noinput in the Dockerfile, it fails because there is no value set for the environment variable DJANGO_SECRET_KEY . My understanding is that this is because config vars aren't available during build time. When I run collectstatic as a release command, it works without error, and successfully copies the static files. However, when I hit the app url, it returns a 500 error because the static files can't

Should I upload images to a static directory in Django?

筅森魡賤 提交于 2020-06-11 08:05:06
问题 I have this model containing an image field. from django.db import models from django.contrib.auth.models import User class Customer(models.Model): user = models.ForeignKey(User) name = models.CharField(max_length=127) logo = models.ImageField(upload_to='customer/logo', null=True, blank=True) def __str__(self): return self.name In my view, I download the image from the specified url and store it in the image field. For testing, I use a test user as foreign key. import json import urllib

How to cache static files in ASP.NET Core?

孤街醉人 提交于 2020-04-18 05:52:06
问题 I can't seem to enable caching of static files in ASP.NET Core 2.2. I have the following in my Configure : public void Configure(IApplicationBuilder app, IHostingEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseCors(...); } else { app.UseHsts(); } app.UseHttpsRedirection(); app.UseAuthentication(); app.UseSignalR(routes => { routes.MapHub<NotifyHub>("/..."); }); app.UseResponseCompression(); app.UseStaticFiles(); app.UseSpaStaticFiles(new StaticFileOptions

Express serve static files in nested directory

巧了我就是萌 提交于 2020-04-11 08:21:29
问题 I am not new to working with express and rendering template views but recently I tried a new directory structure which seems to have confused my app instance. It no longer serves my static bootstrap, css and image files anymore and my view looks all messed up now. Here's my directory structure AppName - node_modules folder - src (all code live here) - public (statics) - css/mycss, bootstrapcss - js/ myjs, bootstrapjs - images folder - models - app.js (entry point) The static files seem to be

Express serve static files in nested directory

Deadly 提交于 2020-04-11 08:21:10
问题 I am not new to working with express and rendering template views but recently I tried a new directory structure which seems to have confused my app instance. It no longer serves my static bootstrap, css and image files anymore and my view looks all messed up now. Here's my directory structure AppName - node_modules folder - src (all code live here) - public (statics) - css/mycss, bootstrapcss - js/ myjs, bootstrapjs - images folder - models - app.js (entry point) The static files seem to be