-1

我的项目名为“tweetme”,当我运行服务器时出现此错误。

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

    ^admin/
    ^static/(?P<path>.*)$

    The empty path 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.

urls.py 文件:

from django.conf.urls import url, include
from django.contrib import admin

from django.conf import settings
from django.conf.urls.static import static


urlpatterns = [
    url(r'^admin/', admin.site.urls),
]

if settings.DEBUG:
    urlpatterns += (static(settings.STATIC_URL,                 
document_root=settings.STATIC_ROOT))

我希望显示:安装成功!祝贺

但它告诉我:页面未找到/

4

1 回答 1

0

您在配置中只定义了两个 url 模式。因此,只有那些才能按预期成功工作。为了使 url / 正常工作,您必须添加额外的 url 模式,如 Django 文档中所述,在相对 url 中使用“”或“/”

https://docs.djangoproject.com/en/2.2/topics/http/urls/#url-namespaces-and-included-urlconfs

于 2019-07-29T08:17:59.960 回答