Django urls.py在尝试访问URL时出现404错误

时间:2013-09-17 19:18:18

标签: python django url url-rewriting http-status-code-404

我正在尝试创建一个使用这两个网址的Django应用程序,浏览和帐户,但是当我尝试访问这两个网址时,我收到了错误。

Using the URLconf defined in mediasite.urls, Django tried these URL patterns, in this order:

^browse/
^admin/

The current URL, browse, didn't match any of these.

查看我的代码后,我不确定错误在哪里。奇怪的是管理网站仍然有效。

urls.py:

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

urlpatterns = patterns('',
    url(r'^browse/', include('media.urls')),

    url(r'^admin/', include(admin.site.urls)),
)

媒体/ urls.py:

from django.conf.urls.defaults import patterns, include, url
from django.views.generic import ListView, DetailView
from media.models import Video

urlpatterns = patterns('',
    url(r'^videos', ListView.as_view(
            queryset=Video.objects.all().order_by("-created")[:2],
            template_name="media.html")),
    url(r'^videos/(?P<pk>\d+)$', DetailView.as_view(
            model=Video,
            template_name="video.html")),
)

settings.py:

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.admin',
    'media',
)

1 个答案:

答案 0 :(得分:1)

看起来media.urls只有两个网址,视频/&amp;视频/包/

这意味着您只有两个网址选项是浏览/视频/和浏览/视频/ pk /

没有网址只是'浏览/'

如果您想添加一个,则需要将其添加到media.urls:

url(r'^$', some_view, name='some_view_name'),