【问题标题】:django The current path,didn't match any of thesedjango 当前路径,不匹配其中任何一个
【发布时间】:2021-03-12 09:19:05
【问题描述】:

我想在 django 中尝试其他应用,但在访问其他应用时遇到问题。

Page not found

树:

主要:

搜索:

  • index.html
  • scrape.html

预处理:

  • index.html

这样的场景。从 scrape.html 我想在预处理中访问 index.html 但找不到错误路径。我已经在 settings.py 中添加了应用程序

主 url.py

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', include('search.urls')),
    path('preprocessing/', include('preprocessing.urls')),
]

搜索 url.py

urlpatterns = [
    path('', views.index,),
    path('scrape/',views.scrape,),
 
]

scrape.html 片段:

 <a href = "/preprocessing" button type="button" class="btn btn-primary" target = "blank">Preprocessing</a>

预处理 url.py

path('', views.index),

让我知道我哪里出错了,谢谢你的帮助

【问题讨论】:

  • 显示您的模板。此外,如果您在设置中为 APPEND_SLASH 设置了值,则会显示。
  • 问题可能出在斜杠中,请尝试在调用它的网址末尾添加/(可能在scrape.html中)
  • 完成,我已经将我的 scrape.html 切片添加到 /preprocessing 和我的 APPEND_SLASH = False @AbdulAzizBarkat
  • 为我的 scrape.html @ErsainD 添加。

标签: python django


【解决方案1】:

你的锚标记写成:

<a href = "/preprocessing" ...>

这里的问题是你的 url 模式就像'preprocessing/',注意它以斜杠结尾,而你的锚 url 没有。此外,在您的设置中设置APPEND_SLASH = False

通常当 Django 发现一个不以斜杠结尾的 url 时,它会在其上附加一个斜杠并将用户重定向到这个新的 url。但是您已经通过设置APPEND_SLASH = False 停止了这种行为。作为第一步,我建议您将其改回APPEND_SLASH = True

接下来,您应该始终命名您的网址并使用这些名称来引用网址。所以你的 urlpatterns 应该是:

主 url.py

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', include('search.urls')),
    path('preprocessing/', include('preprocessing.urls')),
]

搜索 url.py

urlpatterns = [
    path('', views.index, name='index'),
    path('scrape/',views.scrape, name='scrape'),
 
]

预处理 url.py

path('', views.index, name='preprocessing'),

现在在您的模板中,您只需使用url template tag

<a href="{% url 'preprocessing' %}" button type="button" class="btn btn-primary" target = "blank">Preprocessing</a>

【讨论】:

  • ittss 工作,非常感谢先生的帮助和提示
猜你喜欢
  • 1970-01-01
  • 2019-05-18
  • 2020-03-23
  • 2020-11-22
  • 1970-01-01
  • 2020-04-18
  • 2020-01-02
  • 1970-01-01
相关资源
最近更新 更多