python - Django - 为开发 Web 服务器显示 404 页面 (http ://127. 0.0.1:8000/)

标签 python django django-models django-admin django-urls

我正在熟悉 Django。

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

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

  1. 编辑 mysite/settings.py 以启用管理员
  2. 编辑 mysite/url.py 以启用管理员
  3. 删除并重新创建我的后端数据库
  4. 运行 ./manage.py syncdb(并正确响应提示)
  5. 启动开发网络服务器 (./manange.py runserver)

这是我的 mysite/settings.py 文件的样子(仅相关部分)

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    # Uncomment the next line to enable the admin:
    'django.contrib.admin',
    # The next lines are my models
    'mysite.foo',
    'mysite.foobar',
)

这是我的 mysite/urls.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)),

已评论且没有其他网址,django 欢迎页面默认显示在 'http://127.0.0.1:8000/'

关于python - Django - 为开发 Web 服务器显示 404 页面 (http ://127. 0.0.1:8000/),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3890807/

相关文章:

django,在 SQL 中忽略 CharField 默认值

python - Django 过滤器排除外键

python - 如何使用 scipy.io.savemat 附加到 .mat 文件?

python - 获取 bokeh 应用程序的 URL 参数

Python 套接字模块。连接到 HTTP 代理然后对外部资源执行 GET 请求

python - django 在同一模板中为不同的 for 循环重用 html block

python - Django Model 类中的函数不接受 self 参数?

python - 解析 Pandas 列中的列表

python - 使用 django rest 框架的自定义 URL

django - Django 中多个模型的单个自定义管理器