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)),
)
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With