0

I am following the tutorials on The Django Book, and I am tired of getting this error - The current URL, , didn't match any of these. my urls.py is:

from django.conf.urls import include, url
from django.contrib import admin
from mysite.views import hello, current_datetime, hours_ahead

urlpatterns = [
    url(r'^admin/', include(admin.site.urls)),
    url(r'^hello/$', hello),
    url(r'time/$', current_datetime),
    url(r'^time/plus/(\d{1,2})$', hours_ahead),
]

and views.py is:

def current_datetime(request):
    now = datetime.datetime.now()
    html = "It is now %s." % now
    return HttpResponse(html)
def hours_ahead(request, offset):
    try:
       offset = int(offset)
    except ValueError:
       raise Http404()
dt = datetime.datetime.now() + datetime.timedelta(hours = offset)
html = "In %s hour it will be %s" %(offset, dt)
return HttpResponse(html)

and error I'm getting is:

Using the URLconf defined in mysite.urls, Django tried these URL patterns, in this order:

1.^admin/
2.^hello/$
3. time/$
4. ^time/plus/(\d{1,2})$

The current URL, , didn't match any of these.

2 Answers2

0

I had this problem just now. My error was caused by mistyping the development server url.

It needs to be: http://127.0.0.1:8000/polls/

It must have the polls at the end.

This thread also has other solutions to this problem.

Community
  • 1
  • 1
Cyclist
  • 111
  • 1
  • 12
0

Just try to restart your local server and head again to your url http://127.0.0.1:8000/polls/