Django Web 服务器在 IIS 上运行时,不会运行静态 CSS、JS 和图像文件。

huangapple go评论44阅读模式
英文:

django web server running with iis doesn't run static css js image files

问题

我有一个在ISP上运行的Django Web服务器项目,静态文件无法正常工作。

我如何修改Internet Information Services(IIS)和Web配置文件以使静态文件正常工作?

<?xml version="1.0" encoding="UTF-8">

<configuration>

    <appSettings>
    <!-- 必要的设置 -->
    <add key="WSGI_HANDLER" value="django.core.wsgi.get_wsgi_application()" />
    <!-- 你的Django路径 -->
    <add key="PYTHONPATH" value="C:\inetpub\wwwroot\pax_web_server_app" />
    <!-- 你的Django设置 -->
    <add key="DJANGO_SETTINGS_MODULE" value="pax_web_server_app.settings" />
    </appSettings>

    <system.webServer>
        <handlers>

            <add name="paxsite" path="*" verb="*" modules="FastCgiModule" scriptProcessor="C:\Python311\python.exe|C:\Python311\Lib\site-packages/wfastcgi.py" resourceType="Unspecified" />

        </handlers>
        <staticContent>

            <mimeMap fileExtension=".tab" mimeType="static/css" />

        </staticContent>
    </system.webServer>
</configuration>

我按照微软网站上的说明 进行了操作,但仍然无法正常工作。

英文:

I have a django web server project running on ISP and static file is not working

How do I make changes to Internet Information Services (IIS) and web cofig file for static files to work?

&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;

&lt;configuration&gt;

    &lt;appSettings&gt;
    &lt;!-- Required settings --&gt;
    &lt;add key=&quot;WSGI_HANDLER&quot; value=&quot;django.core.wsgi.get_wsgi_application()&quot; /&gt;
    &lt;!-- Your django path --&gt;
    &lt;add key=&quot;PYTHONPATH&quot; value=&quot;C:\inetpub\wwwroot\pax_web_server_app&quot; /&gt; 
    &lt;!-- Your djangoname.settings --&gt;
    &lt;add key=&quot;DJANGO_SETTINGS_MODULE&quot; value=&quot;pax_web_server_app.settings&quot; /&gt;
    &lt;/appSettings&gt;

    &lt;system.webServer&gt;
        &lt;handlers&gt;

            &lt;add name=&quot;paxsite&quot; path=&quot;*&quot; verb=&quot;*&quot; modules=&quot;FastCgiModule&quot; scriptProcessor=&quot;C:\Python311\python.exe|C:\Python311\Lib\site-packages\wfastcgi.py&quot; resourceType=&quot;Unspecified&quot; /&gt;

        &lt;/handlers&gt;
        &lt;staticContent&gt;

            &lt;mimeMap fileExtension=&quot;.tab&quot; mimeType=&quot;static/css&quot; /&gt;

        &lt;/staticContent&gt;
    &lt;/system.webServer&gt;
&lt;/configuration&gt;

I did the instructions on the microsoft website but it still didn't work

答案1

得分: 0

创建名为static的IIS虚拟目录,并将该虚拟目录的路径指向您的实际静态文件夹。

以下是有关更多详细信息的链接:
https://stackoverflow.com/questions/32312590/how-to-fetch-static-css-files-with-django-on-iis

英文:

Create virtual directory in iis with the name of static and point the path to that virtual directory with your actual static folder

Here is the link you can refer for the more details:

https://stackoverflow.com/questions/32312590/how-to-fetch-static-css-files-with-django-on-iis

huangapple
  • 本文由 发表于 2023年2月8日 16:55:52
  • 转载请务必保留本文链接:https://go.coder-hub.com/75383317.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定