Editing
Running a Django Application on IIS
(section)
Jump to navigation
Jump to search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== Static files === With the preceding `web.config` configuration, all the requests are routed to the Django application. However, we want the static files of our application to be managed by IIS itself. To do that, we first configure Django to collect the static files in the `static` subdirectory of our project. For that, we have the following configuration in our `settings.py` file: <syntaxhighlight lang="python"> SITE_ROOT = os.path.abspath(os.path.dirname(__file__)) ... STATIC_URL = '/static/' ... STATIC_ROOT = os.path.join( SITE_ROOT, 'static') SITE_STATIC_ROOT = os.path.join( SITE_ROOT, 'local_static') # Additional locations of static files STATICFILES_DIRS = ( # Don't forget to use absolute paths, not relative paths. ('', SITE_STATIC_ROOT), ) .. </syntaxhighlight> The project wide defined static files are located in the `local_static` directory. All the static files are collected in the `static` directory by running the following command: <syntaxhighlight lang="bash"> python manage.py collecstatic </syntaxhighlight> In the `local_static` directory we put the following `web.config` file: <syntaxhighlight lang="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> </syntaxhighlight> Which basically inverts the `web.config` file or the root of the project by clearing all the handlers and serving all requests only as static files. When collected, this file will go in the `static` directory and will instruct IIS that all requests below the path `/static` should be served as static files.
Summary:
Please note that all contributions to Littledamien Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Littledamien Wiki:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Navigation menu
Personal tools
Not logged in
Talk
Contributions
Create account
Log in
Namespaces
Page
Discussion
English
Views
Read
Edit
View history
More
Search
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Tools
What links here
Related changes
Special pages
Page information