Python django正在将空白url重定向到命名url
我有我的网址:Python django正在将空白url重定向到命名url,python,django,url,Python,Django,Url,我有我的网址: url(r'^home/', HomeQuestionView, name='home_question') , 当我进入localhost:8000/home时,我会得到我的主页,但我想要的是当我刚刚进入时,我会得到我的主页。 我的意思是,当用户只进入我的网站时,我想重定向到上面的主页url,如www.xyz.comnotwww.xyz.com/home 我不想这样配置 url(r'^', HomeQuestionView, name='home_question') ,
url(r'^home/', HomeQuestionView, name='home_question') ,
当我进入localhost:8000/home
时,我会得到我的主页,但我想要的是当我刚刚进入时,我会得到我的主页。
我的意思是,当用户只进入我的网站时,我想重定向到上面的主页url,如www.xyz.com
notwww.xyz.com/home
我不想这样配置
url(r'^', HomeQuestionView, name='home_question') ,
Thanx提前使用通用:
我找到了这个解决方案(长话短说,您需要将views.py添加到您的主项目文件夹中,并创建将空路由重定向到url的视图):
urlpatterns = [
...
path("", views.home, name="home"),
...
]
from django.shortcuts import render, redirect
def home(request):
return redirect("blog:index") # redirect to your page
您不想使用r'^'配置的原因是什么?您不想做能让您的站点按您想要的方式工作的事情吗?
from django.shortcuts import render, redirect
def home(request):
return redirect("blog:index") # redirect to your page