0

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

我尝试了三遍,但我几乎已经正确安装了 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)),
)
4

1 回答 1

0

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

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

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

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

于 2013-10-08T00:23:20.393 回答