Sooraj
Sooraj

Reputation: 10577

Page not found in Django

I'm following this tutorial to learn Django. I'm a total starter. My urls.py file has following code

from django.conf.urls import include, url
from django.contrib import admin
from . import views

urlpatterns = [
    url(r'^$', views.index, name='index'),
    url(r'^polls/', include('polls.urls')),
    url(r'^admin/', include(admin.site.urls)),

 ]

My views.py file is

from django.shortcuts import render

def index(request):
 return HttpResponse("Hello, world. You're at the polls index.")

When i try to access th url http://127.0.0.1:8000/polls/ in my system it gives a page not found message. What am i doing wrong? Is it a problem with the version difference?

Here is the screenshot of the error enter image description here

Upvotes: 0

Views: 264

Answers (2)

Naman Sogani
Naman Sogani

Reputation: 959

This error comes if your urls.py file in polls directory does not have this pattern. Create a file urls.py your polls directory and add following url pattern

from django.conf.urls import patterns, url
from polls import views

urlpatterns = patterns('',
# ex: /polls/
url(r'^$', views.index, name='index'),
)

Upvotes: 1

dydek
dydek

Reputation: 348

Ok, so if you want to use /polls/ with this urls, your polls.urls should look similar to this ( for django1.8):

from django.conf.urls import url
from polls.views import BasePollView, AnotherPollView

urlpatterns = [
    url(r'^$', BasePollView.as_view()),
    url(r'^another-url/$', AnotherPollView.as_view())
]

/polls/ -> BasePollView

/polls/another-url/ -> AnotherPollView

Upvotes: 1

Related Questions