【发布时间】:2017-06-01 18:58:11
【问题描述】:
当我尝试导航到我的 django 应用程序的管理部分时,我收到一个未找到的错误:
项目/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')),
]
项目/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'),)
....
当我尝试导航到 localhost:8000/admin 时,我收到以下错误:
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.
【问题讨论】: