Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Django-404页面显示用于开发web服务器(http://127.0.0.1:8000/)_Python_Django_Django Models_Django Admin_Django Urls - Fatal编程技术网

Python Django-404页面显示用于开发web服务器(http://127.0.0.1:8000/)

Python Django-404页面显示用于开发web服务器(http://127.0.0.1:8000/),python,django,django-models,django-admin,django-urls,Python,Django,Django Models,Django Admin,Django Urls,我正在熟悉Django 我已经成功安装并测试了一个演示站点。我现在想打开管理模块,看看会发生什么 我采取的步骤(当然,有些是不必要的,但我只是想确保我是从一个干净的开始): 编辑mysite/settings.py以启用管理 编辑mysite/url.py以启用管理 删除并重新创建了我的后端数据库 运行./manage.py syncdb(并正确响应提示) 已启动开发web服务器(./manange.py runserver) 以下是我的mysite/settings.py文件的外观(仅适用于相

我正在熟悉Django

我已经成功安装并测试了一个演示站点。我现在想打开管理模块,看看会发生什么

我采取的步骤(当然,有些是不必要的,但我只是想确保我是从一个干净的开始):

  • 编辑mysite/settings.py以启用管理
  • 编辑mysite/url.py以启用管理
  • 删除并重新创建了我的后端数据库
  • 运行./manage.py syncdb(并正确响应提示)
  • 已启动开发web服务器(./manange.py runserver)
  • 以下是我的mysite/settings.py文件的外观(仅适用于相关部分)

    以下是我的mysite/url.py文件的外观:

    from django.contrib import admin
    admin.autodiscover()
    
    urlpatterns = patterns('',
        # Example:
        # (r'^mysite/', include('mysite.foo.urls')),
    
        # Uncomment the admin/doc line below and add 'django.contrib.admindocs' 
        # to INSTALLED_APPS 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)),
    )
    
    当我浏览到服务器url时,我得到以下响应:

    Page not found (404)
    Request Method:     GET
    Request URL:    http://127.0.0.1:8000/
    
    Using the URLconf defined in mysite.urls, Django tried these URL patterns, in this order:
    
       1. ^admin/doc/
       2. ^admin/
    
    The current URL, , didn't match any of these.
    
    You're seeing this error because you have DEBUG = True in your Django settings file. Change that to False, and Django will display a standard 404 page.
    

    我做错了什么?

    很明显,您没有任何url来处理请求'http://127.0.0.1:8000/"

    要查看管理页面,请访问'http://127.0.0.1:8000/admin/"

    当您有管理员URL时

    # (r'^admin/doc/', include('django.contrib.admindocs.urls')),
    
    # Uncomment the next line to enable the admin:
    # (r'^admin/', include(admin.site.urls)),
    
    在没有其他URL的情况下,django欢迎页面默认显示在'http://127.0.0.1:8000/“

    请求URL:

    您正在访问根URL。但是,您没有与此匹配的URL配置。您的管理应用程序位于
    http://127.0.0.1:8000/admin/
    。试试看

    如果您希望管理员应用程序在根目录下可访问,则必须更改URL映射,如下所示:

    urlpatterns = patterns('',
         # Uncomment the next line to enable the admin:
        (r'^$', include(admin.site.urls)),
    )
    
    请记住,不建议这样做。您当然不希望根URL指向管理员应用程序

  • 使用PyCharm 2.7
  • 位置:url.py
  • 这一行(在url.py中)url(r'^admin/',include(admin.site.url)),没有注释。添加了#和瞧,页面工作
    urlpatterns = patterns('',
         # Uncomment the next line to enable the admin:
        (r'^$', include(admin.site.urls)),
    )