Search code examples
djangofastcgidjango-staticfilesiis-10

How to access different static files for different Django applications on IIS?


Suppose I have two Django apps: DjangoApp1 and DjangoApp2
I have created a website with DjangoApp1 in IIS with some IP(192.168.1.1) on port 80, and I can access this website on 192.168.1.1/, the static files are loaded by the virtual directory static, and this site is seen perfectly as expected.

Now, for the second app, DjangoApp2, I need to access it through the same IP address in this way: 192.168.1.1/app2/, so I created an Application in my website with the name app2 and configured it accordingly. Now, since DjangoApp2 has a different set of static files, I need to configure my server so that it loads those files as well. Since I already have a virtual directory named static, I can't create one with the same name. I tried creating app2_static and all other combinations, but these files were not loading. All the other functionalities of this app work correctly, which are not dependent on the local static files.


How do I configure the StaticFileModule so that it loads the necessary files for DjangoApp2, without disturbing the files of DjangoApp1?

I have used FastCgi and wfastcgi module of Django for the deployment configurations.


Solution

  • Found the solution myself when I was messing around with the settings.py file of my "DjangoApp2". I first considered to add the static files of my DjangoApp2 to the static directory of DjangoApp1, but I thought it could be very inefficient, so I started tweaking some changes in my settings.py file.
    So, instead of changing something in the IIS server, I simply changed my STATIC_URL.

    So, first I created a virtual directory for my static files and named it app2_static. Its physical path was BASE_DIR/static.

    The BASE_DIR is the directory where the manage.py file of DjangoApp2 is located.

    Then, I changed the STATIC_URL to '/app2_static/'. Then I restarted the IIS server and the static files were loading on the webpage.

    Make sure that your web.config file in the static directory of your DjangoApp2 contains only StaticFileModule and no FastCGIModule.