Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

django tried these url patterns

When I try to access my site, it gives me the following: Using the URLconf defined in mysite.urls, Django tried these URL patterns, in this order: ^admin/ The current URL, , didn't match any of these.

If I go to the site and append /admin, it takes me to the admin page. If I comment out the line enabling the admin, it works properly. How do I get both? The first pattern in urlpatterns is '', so I don't understand why that messes up when I enable the admin. (Note: I am just doing the tutorial.)

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

# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
# Examples:
#url(r'^$', 'mysite.views.home', name='home'),
# url(r'^x/', include('mysite.foo.urls')),

# Uncomment the admin/doc line below to enable admin documentation:
# url(r'^admin/doc/', include('django.contrib.admindocs.urls')),

# Uncomment the next line to enable the admin:
url(r'^admin/', include(admin.site.urls)),
)
like image 273
user2258552 Avatar asked Feb 16 '23 18:02

user2258552


1 Answers

This is a common problem.

When there are no urlpatterns defined at all, Django gives you the "It worked! Congratulations on your first Django-powered page" message, but as soon as you define any urlpattern that goes away.

You're getting that error because you have not defined a urlpattern for the root url, just one for "/admin". Continue through the tutorial until it teaches you how to add your own urlpatters.

like image 180
Hamms Avatar answered Feb 27 '23 22:02

Hamms