Django in sub-directory
<p>When i build my django application, i'll use the runserver command in order to test my website, but in deploy, let's say that i'll publish my website under: www.test.com/django.</p>

<p>My IIS it's configure with an application under my default website called "django".</p>

<p>I'm expecting that everything will works fine, but django doesn't recognize my url schema, that is the following one:</p>

<pre><code>urlpatterns = [
    # Examples:
    url(r'^$', app.views.home, name='home'),
    url(r'^contact$', app.views.contact, name='contact'),
    url(r'^about', app.views.about, name='about'),
]
</code></pre>

<p>and in this case, i need to modify my urlpatterns like this, in order to serve the application via www.test.com/django:</p>

<pre><code>urlpatterns = [
    url(r'^(?i)django/', include([ #Application name
        # Examples:
        url(r'^$', app.views.home, name='home'),
        url(r'^contact$', app.views.contact, name='contact'),
        url(r'^about', app.views.about, name='about'),
    ])),
]
</code></pre>

<p>It's a good approach? it's working but i'm not sure about the quality of this solution.</p>

<p>The preferred method to fix this is to have your webserver pass the <code>SCRIPT_NAME</code> wsgi variable. Django will automatically use this variable as a prefix when constructing urls, without the need to change your url configuration. I'm unfamiliar with IIS, so I can't tell you how to do this. It does have the advantage that your code is completely agnostic to the actual mount point of your WSGI application, as the script name is passed to Django rather than configured in its settings. </p>

<p>Alternatively, you can set the <a href="https://docs.djangoproject.com/en/1.10/ref/settings/#force-script-name" rel="nofollow"><code>FORCE_SCRIPT_NAME</code></a> setting to <code>/django/</code>. </p>

python django url