简体   繁体   English

Python Django 奇怪地映射到意外的 URL

[英]Python Django strangely does mapping towards unexpected URL

I tested 1st Django web app project.我测试了第一个 Django web 应用程序项目。
That app project redirects to http://127.0.0.1:8000/api/ when the URL of http://127.0.0.1:8000 is visited.当访问http://127.0.0.1:8000的 URL 时,该应用程序项目重定向到http://127.0.0.1:8000/api/ The test was successful.测试成功。

And then, I tested 2nd Django web app project.然后,我测试了第二个 Django web 应用程序项目。
That Django app should have redirected to http://127.0.0.1:8000/blog/ when the URL of http://127.0.0.1:8000 is visited but Django strangely redirects to http://127.0.0.1:8000/api/ which was target URL of 1st Django web app. That Django app should have redirected to http://127.0.0.1:8000/blog/ when the URL of http://127.0.0.1:8000 is visited but Django strangely redirects to http://127.0.0.1:8000/api/这是第一个 Django web 应用程序的目标 URL。

There is no /api/ URL configuration in 2nd project第二个项目中没有/api/ URL 配置
Following code snippets are URL configuration of 2nd Django web app以下代码片段是第二个 Django web 应用程序的 URL 配置

# AskDjango_webfrontend_begin/askdjango/urls.py
urlpatterns = [
    path('admin/', admin.site.urls),

    # If the client enters in "localholst:8000", the page is redirected to localholst:8000/blog/
    path("", RedirectView.as_view(url="/blog/", permanent=True)),

    # If the client enters in "localholst:8000/blog/", connect to blog.urls.py
    path("blog/", include("blog.urls")),
]
# AskDjango_webfrontend_begin/blog/urls.py
urlpatterns = [
    path("",views.index,name="index"),
    path('<int:pk>', views.post_detail, name="post_detail")
]

Your browser has cached the 302 Redirect HTTP response from the first URL.您的浏览器已缓存来自第一个 URL 的302 Redirect HTTP 响应。 Clear your cache and try again.清除缓存并重试。

I recommend you to use different hostnames (such as 127.0.0.1 and 127.0.0.2 ) while testing multiple web applications running on the same development PC.我建议您在测试在同一台开发 PC 上运行的多个 web 应用程序时使用不同的主机名(例如127.0.0.1127.0.0.2 )。

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

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