Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django - The current URL, , didn't match any of these

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

#urlpatterns = [
#    url(r'^mypage/', include('mypage.urls')),
#    url(r'^admin/', admin.site.urls),
#]


urlpatterns = patterns('',
url(r'^$', 'mypage.views.home', name='home'),
url(r'^admin/', admin.site.urls),
)

The uncommented code is working fine. But as per tutorials the commented code also should have to work. But its showng an error of "The current url didnt match any of these". The code path is /ownblog/ownblog/urls.py

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

The above code is in ownblog/mypage/urls.py

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

The above code is in ownblog/mypage/views.py What I am missing

like image 517
Ravi Shanker Reddy Avatar asked Apr 20 '16 12:04

Ravi Shanker Reddy


Video Answer


1 Answers

The error message when you visit http://localhost:8000/ is expected, because you haven't defined a url pattern for / in your commented code. The tutorial tells you to go to http://localhost:8000/polls/. In your case, change that to http://localhost:8000/mypage/ because you use mypage instead of polls.

The second error No module named views is because you have used the string 'views.home' in your url patterns instead of the callable views.home. Make sure you include the import as well.

from . import views

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

I notice that you are not following the 1.9 tutorial very closely. For example you are using patterns() and strings like 'mypage.views.home', which are both outdated since Django 1.8. I think you'd find it useful to follow the tutorial exactly before you begin changing lots of stuff.

like image 135
Alasdair Avatar answered Oct 18 '22 22:10

Alasdair