Flask静态文件夹未在IIS上提供 [英] Flask static folder not served on IIS

查看:91
本文介绍了Flask静态文件夹未在IIS上提供的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在IIS上的网站下提供应用程序,但无法访问静态文件夹(我的CSS文件和图片在哪里).我按照提示尝试了一些选项(

我的应用程序在线,但是没有CSS和图片.

解决方案是什么?感谢您的帮助!

在2月1日进行修改:

解决方案

我认为静态文件夹不需要使用虚拟目录.

这是我的演示:

我使用VS中的默认模板创建了Flask项目,并将其发布到了文件夹中:

web.config如下:

 <?xml version ="1.0"encoding ="UTF-8"?<配置>< system.webServer><处理程序>< add name ="Flask"path ="*"动词="*"modules ="FastCgiModule"scriptProcessor ="C:\ Python \ python.exe | C:\ Python \ lib \ site-packages \ wfastcgi.py"resourceType =未指定"/></handlers><安全性>< requestFiltering allowDoubleEscaping ="true"></requestFiltering></security></system.webServer>< appSettings><!-必需的设置-><添加密钥="WSGI_HANDLER";value ="FlaskWebProject1.app"/>< add key ="PYTHONPATH";值=〜/"/></appSettings></configuration> 

此项目在IIS中的目录结构如下:

UDDATE:

应注意,将静态文件添加为虚拟目录时,必须将其添加到主应用程序下.

静态文件夹必须与flask处于同一级别.因为默认情况下,在主应用程序下请求对静态文件的请求:

I serve an application under a website on IIS but I can't access static folder (where are my CSS files and pictures). I tried few options following tips (IIS7, web.config to allow only static file handler in directory /uploads of website and How to fetch static CSS files with django on IIS?) but neither works.

My structure on IIS is below with static as a virtual directory of the app:

My app is online but without CSS and pictures.

What is the solution? Thanks for your help!

Edit on 1st of February:

解决方案

I think static folder does not need to use virtual directory.

Here is my demo:

I created a Flask project using the default template in VS and published it to the folder:

web.config is as follows:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <handlers>
            <add name="Flask" path="*" verb="*" modules="FastCgiModule" scriptProcessor="C:\Python\python.exe|C:\Python\lib\site-packages\wfastcgi.py" resourceType="Unspecified" />
        </handlers>
                <security> 
            <requestFiltering allowDoubleEscaping="true"></requestFiltering> 
        </security> 
    </system.webServer>
       <appSettings>
        <!-- Required settings -->
        <add key="WSGI_HANDLER" value="FlaskWebProject1.app" />
        <add key="PYTHONPATH" value="~/" />
    </appSettings>
</configuration>

The directory structure of this project in IIS is as follows:

UDDATE:

It should be noted that when adding static files as virtual directories, they must be added under the main application.

The static folder needs to be at the same level as flask.Because the request for static files by default is requested under the main application:

这篇关于Flask静态文件夹未在IIS上提供的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆