Django flaky url (randomly omits WSGIScriptAlias)

31 views Asked by At

My Django site is producing URLs that intermittently omit my WSGIScriptAlias. If I simply print out {% url 'index' %} in my index.html (see my urls.py settings below) I randomly (around 50% of the time) get either:

MySiteAlias/MySite 

which is correct, or

MySite/

which is incorrect.

myapp/urls.py:

from django.conf.urls import url,include

urlpatterns = [
    url(r'^MySite/', include('mysite.urls')),
]

mysite/urls.py:

from django.conf.urls import url
from . import views

urlpatterns = [
    url(r'^$', views.index, name='index'),
]

and views.index basically does return render(request, 'mysite/index.html). Any ideas on how to fix this?

1

There are 1 answers

0
Sayse On BEST ANSWER

I'd imagine you might have two urls with the same name, this is where namespaces will help. If you provide a namespace for your mysite.urls then there is no confusion on where you should go to

url(r'^MySite/', include('mysite.urls', namespace='mysite')),
{% url 'mysite:index' %}