【问题标题】:Django admin panel works but main page gives me a 404Django 管理面板有效,但主页给了我一个 404
【发布时间】:2013-10-13 10:40:26
【问题描述】:

我是 Django 和 Python 的新手。我只做过php。

我尝试了 3 次,但我几乎已经正确安装了 Django。我按照教程安装它,它工作。所以我启用了管理员、面板并设置了 mysql。

管理面板正常工作,我有我的静态文件夹,所以它也有所有的 css。但是当我进入主页时,我得到了这个 404。(我的项目名为 firstweb)所以当我进入 firstweb 时,有一个 404,但 firstweb/admin 工作。

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

 1.   ^admin/

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

我对整个 runserver 的事情感到困惑。那是不是我的 Apache 以外的其他小服务器?为什么每次都需要启动?

from django.conf.urls import patterns, include, url

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

urlpatterns = patterns('',
# Examples:
# url(r'^$', 'firstweb.views.home', name='home'),
# url(r'^firstweb/', include('firstweb.foo.urls')),

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

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

【问题讨论】:

  • 默认情况下,django pre 1.5 未启用管理员,请按照此处的步骤操作:docs.djangoproject.com/en/1.5/ref/contrib/admin/#overview
  • runserver 仅用于本地开发,不适用于在生产中运行您的站点。
  • Karth,管理面板已启用并且可以正常工作。我提到过。主页有404。管理员零问题。
  • @gregor - 根据您的 urls.py 文件的顺序,它可能会拾取各个管理页面,但不会拾取主页。你能显示你的 urls 文件吗?顺序可能很重要。
  • @Joseph,将其添加到上面的 OP 中。

标签: django debian django-urls django-settings


【解决方案1】:

看起来您的 url conf 不包含任何其他页面接受管理员的任何 url 模式。

如果您希望根 url 显示页面,请取消注释此行

url(r'^$', 'firstweb.views.home', name='home'),

然后确保在 firstweb/views.py 中有一个名为“home”的视图函数,我认为这是教程的一部分。

【讨论】:

    猜你喜欢
    • 2017-06-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-28
    • 1970-01-01
    • 2011-04-21
    • 1970-01-01
    • 2020-12-14
    • 1970-01-01
    相关资源
    最近更新 更多