62👍
After struggling for 2 days, for the sake of those who have the same problem, I wanted to share a step-by-step solution for (probably a common) issue.
Problem
You have started a django project on IIS and it is working perfectly on your localhost. Now, when deploying it to web-server, the static files (CSS, JS, images,..) are not fetched. You can read here and here , but in fact, you don’t want all these configurations and copying files from one directory to another…
What you want is that your IIS server will fetch the static files from the static/ directory, just as the development server (the one you run with python manage.py runserver) did.
Solution
-
inside the static/ directory, create a new file called web.config (notice, you probably have another web.config file in upper directory – don;t touch it. just leave it as is).
-
Write the following as the content of this file:
-
Go to your IIS server -> right click the site name -> Add virtual directory
-
in alias wrote "static" (This is a MUST). Then, navigate to the folder in the project where all the static files are
- run IIS server and enter your website. It should work.
21👍
Yura’s answer is quite complete. I had another approach, thought.
Right click the website and go to add application, enter the alias(used ‘static’) and then enter the physical path to your static files folder. Press OK.
Now, the tricky part, in the application you created for the static folder, go to the handle mapping and delete the mapping to the FastCGI site handler.
Enter your site, it works!
It’s pretty similar to Yura’s answer, but uses the IIS interface instead of writing a web.config file by yourself.
- [Django]-How to update code in a docker container?
- [Django]-Programmatically saving image to Django ImageField
- [Django]-NameError: name '_mysql' is not defined after setting change to mysql