[Django]-Django 1.8.3 urls

4👍

Your url pattern index is catching all urls. This means that any url patterns below will be ignored.

url('^.*$', IndexView.as_view(), name='index'),

To match only the index (i.e. http://127.0.0.1:8000/), change it to

url(r'^$', IndexView.as_view(), name='index'),

Note that I’ve also added the r'' prefix to the regex. It doesn’t make any difference in this case, but it’s a good habit to use it in your regexes.

0👍

In MyProj/urls.py

urlpatterns = [
    url(r'^admin/', include(admin.site.urls)),
    url('^$', IndexView.as_view(), name='index'),
    url(r'^questions$', views.home, name='home'),
]

questions/urls.py:

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

questions/views.py

def home(request):
    return render(request, "questions/home.html", {})

Leave a comment