Reputation: 732
When I try to navigate to the admin section of my django app, I get a not found error:
project/urls.py
from django.conf.urls import include, url
from django.contrib import admin
from app.views import View1, View2
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
url(r'^$', View1.as_view(), name="view_1"),
url(r'^another_view/(?P<pk>\d+)$', View2.as_view(), name="view_2"),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
app/urls.py
from django.conf.urls import include, url
from django.contrib import admin
urlpatterns = [
url(r'^admin/', include(admin.site.urls)),
(r'^/', include('project.urls')),
]
project/settings.py
....
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATIC_URL = '/static/'
STATICFILES_DIRS = ( os.path.join(BASE_DIR, 'app/static'),)
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = '/media/'
MEDIAFILES_DIRS = ( os.path.join(BASE_DIR, 'app/media'),)
....
When I try to navigate to localhost:8000/admin, I get the following error:
Page Not Found (404)
Using the URLconf defined in app.urls, Django tried these URL patterns, in this order:
^$ [name='view_1']
^another_view$ [name='view_2']
^media\/(?P<path>.*)$
The current URL, admin, didn't match any of these.
Upvotes: 0
Views: 1462
Reputation: 599600
You have the app and project urls the wrong way round.
The project urls should contain the mapping for the admin, and include the app urls; the app urls in turn should contain the specific mappings for the app views.
The static stuff should still be in the project urls though; although you shouldn't need it in any case.
Upvotes: 2