Django总是给404

时间:2011-03-02 16:00:20

标签: django

我的Django项目总是给我一个404,无论我试图访问哪个页面。作为Django noob,我不知道如何解决这个问题。有什么建议吗?

编辑:这是我的urls.py

from django.conf.urls.defaults import *

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

urlpatterns = patterns('',
    # Example:
    # (r'^mcifdjango/', include('mcifdjango.foo.urls')),

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

    # Uncomment the next line to enable the admin:
    # (r'^admin/', include(admin.site.urls)),
)

2 个答案:

答案 0 :(得分:3)

您期待什么样的行为?

您没有将网址映射到任何内容 - 您应该只能获得404!

import http

def a_view(request):
    return http.HttpResponse("My first mapped url")

urlpatterns = patterns('',
    (r'^$', a_view), # my first url mapped to anything
    (r'^second_url/$', a_view), # my second non 404 url
)

答案 1 :(得分:0)

您必须在urls.py中添加从网址到视图的映射。有关更多信息:

http://docs.djangoproject.com/en/dev/topics/http/urls/