admin管理员组

文章数量:1655035

 

基于windows10系统部署django项目

假设已搭建python环境,以及django项目已进行静态资源的收集(python manage.py collectstatic)

操作步骤:

1. 开启IIS

 

 

 2. 安装 wfastcgi,并启动

以管理员打开cmd命令安装:pip install  wfastcgi, 再次输入命令:wfastcgi-enable,会生成一个路径,将它保存下来

3. 从安装包中复制一份wfastcgi.py文件到项目根目录中,项目最好放置在C:/inetpub/wwwroot/ 中,便于管理

 4. 在根目录中新建一个web.config文件,内容如下:

<?xml version="1.0" encoding="UTF-8"?>
    <configuration>
        <system.webServer>
            <handlers>
                <add name="Python FastCGI"
                     path="*"
                     verb="*"
                     modules="FastCgiModule"
                     scriptProcessor="第2步保存的路径"
                     resourceType="Unspecified"
                     requireAccess="Script"/>
            </handlers>
        </system.webServer>
        <appSettings>
            <add key="WSGI_HANDLER" value="django.core.wsgi.get_wsgi_application()" />
            <add key="PYTHONPATH" value="项目根目录" />
            <add key="DJANGO_SETTINGS_MODULE" value="项目名称.settings" />
        </appSettings>
    </configuration>

5. 打开管理工具,进入IIS管理器,添加网站,并浏览

 

 6. 遇见的错误

6.1

解决方法:

 在IIS管理器中,进入应用程序池

 

 6.2 访问页面或单独访问网站,后台出现400错误,这可能是因为没有给网站权限的原因

 

配置静态文件

django项目中设置settings.py

添加STATIC_ROOT = os.path.join(BASE_DIR, 'static'), debug = False

在项目文件下执行 python manage.py collectstatic

在根目录下的static中新建web.xml文件,内容如下:

 

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <!-- this configuration overrides the FastCGI handler to let IIS serve the static files -->
    <handlers>
    <clear/>
      <add name="StaticFile" path="*" verb="*" modules="StaticFileModule" resourceType="File" requireAccess="Read" />
    </handlers>
  </system.webServer>
</configuration>

 【参考】

https://wwwblogs/djangocn/p/10227006.html

https://blog.csdn/gdali/article/details/83018529

本文标签: 项目系统django