gpt4 book ai didi

python - webroot 上的 django urlconf 404

转载 作者:太空宇宙 更新时间:2023-11-03 17:18:08 24 4
gpt4 key购买 nike

  • Django:1.8.5
  • Python:3.5

我仅在 Webroot 上收到 404 错误。我不知道我的 urlconf 有什么问题。

目录结构:

myproject        // from django-admin startproject
myproject // '' ''
__init__.py
settings.py
urls.py
views.py
myapp // from manage.py startapp
migrations
__init__.py
admin.py
models.py
tests.py
urls.py
views.py

在我的项目中> urls.py:

from django.conf.urls import include, url, patterns
from myapp import urls as app_urls


urlpatterns = patterns('',
url(r'^/$', include(app_urls)),
)

在 myapp > urls.py 中:

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

urlpatterns = patterns('',
url(r'^/$', 'index'),
)

我运行 django 开发服务器,尽管我定义了空的正则表达式,但我在索引页上得到了 404。

Using the URLconf defined in myproject.urls, Django tried these URL patterns, in this order:
^/$
The current URL, , didn't match any of these.

全新安装的 django 中的 urls.conf 中的文档:

Including another URLconf
1. Add an import: from blog import urls as blog_urls
2. Add a URL to urlpatterns: url(r'^blog/', include(blog_urls))

将两个 urls.py 文件中的正则表达式更改为 r'^' 似乎有效,但出现新的 'Could not import 'index'. 错误。

最佳答案

使用 include 时,不要使用 $。将其更改为:

# myproject/urls.py

from django.conf.urls import include, url, patterns
from myapp import urls as app_urls


urlpatterns = patterns('',
url(r'^', include(app_urls)),
)

# myapp/urls.py

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

urlpatterns = patterns('',
url(r'^$', 'index'),
)

关于python - webroot 上的 django urlconf 404,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33444096/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com