使用localhost:8000/admin/
和localhost:8000/
效果很好。你知道吗
但我想忽略其他毫无意义的链接,比如本地主机:8000/adm让他们回到本地主机:8000/永久地。你知道吗
from django.urls import path
from django.conf import settings
from django.conf.urls import include, url
from django.contrib import admin
from django.views.generic import RedirectView
from API import views
from API.views.Home import HomeView
urlpatterns = [
path('grappelli/', include('grappelli.urls')), # grappelli URLS
url(r'^admin/', admin.site.urls),
url(r'^v1/', include('API.urls')),
url(r'',HomeView.as_view(),name='HomeView'),
]
你知道吗?这可以简单地通过regex实现吗?你知道吗
更多示例。。。我想要达到的目标
localhost:8000/anything -> localhost:8000/
localhost:8000/anything/ -> localhost:8000/
localhost:8000/admin/anything -> localhost:8000/admin/
localhost:8000/admin/anything/ -> localhost:8000/admin/
简而言之,我想去掉多余的URL部分,这样它们甚至不会在浏览器中显示5xx重定向。你知道吗
在nginx中可以很容易地完成,但是我想知道在django中是否可以直接完成。你知道吗
使用regex的解决方案是:
但这会将原始url留在地址栏中。你知道吗
要摆脱它,请将重定向视图子类化:
相关问题 更多 >
编程相关推荐