简体   繁体   English

django 当前路径,不匹配任何这些

[英]django The current path,didn't match any of these

i want to try another apps in django but i got problem when access another apps.我想在 django 中尝试其他应用程序,但访问其他应用程序时出现问题。

Page not found网页未找到

tree:树:

main:主要的:

search:搜索:

  • index.html索引.html
  • scrape.html刮擦.html

preprocessing:预处理:

  • index.html索引.html

the scenario like this.像这样的场景。 from scrape.html i want to access index.html in preprocessing but got an error path not found.从 scrape.html 我想在预处理中访问 index.html 但找不到错误路径。 I've done to add apps in settings.py我已经在 settings.py 中添加了应用程序

main url.py主要 url.py

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

search url.py搜索 url.py

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

slice of scrape.html:刮片。html:

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

preprocessing url.py预处理 url.py

path('', views.index),

let me know where did I go wrong, thx for your help让我知道我在哪里 go 错了,谢谢你的帮助

Your anchor tag is written as:您的锚标记写为:

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

The problem here is that your url pattern is like 'preprocessing/' , notice that it ends in a trailing slash while your anchors url doesn't.这里的问题是您的 url 模式就像'preprocessing/' ,请注意它以斜杠结尾,而您的锚点 url 没有。 Furthermore in your settings you set APPEND_SLASH = False .此外,在您的设置中设置APPEND_SLASH = False

Normally when Django finds a url not ending in a trailing slash it appends a slash to it and redirects the user to this new url.通常,当 Django 发现 url 没有以斜杠结尾时,它会在其上附加一个斜杠并将用户重定向到这个新的 Z572D4E421E5E6B9BC11D815E8A027112。 But you have stopped this behaviour by setting APPEND_SLASH = False .但是您已经通过设置APPEND_SLASH = False停止了这种行为。 As the first step I would advice you to change this back to APPEND_SLASH = True .作为第一步,我建议您将其改回APPEND_SLASH = True

Next you should always name your urls and use those names to refer to the urls.接下来,您应该始终命名您的网址并使用这些名称来引用网址。 So your urlpatterns should be:所以你的 urlpatterns 应该是:

main url.py主要 url.py

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

search url.py搜索 url.py

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

preprocessing url.py预处理 url.py

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

Now in your templates you would simply use the url template tag :现在在您的模板中,您只需使用url模板标签

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM