Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python “Django重定向”/&引用;为已安装的应用程序编制索引_Python_Django_Url_Redirect_Indexing - Fatal编程技术网

Python “Django重定向”/&引用;为已安装的应用程序编制索引

Python “Django重定向”/&引用;为已安装的应用程序编制索引,python,django,url,redirect,indexing,Python,Django,Url,Redirect,Indexing,我正在尝试重定向域的/以指向我的“前端”应用程序中的索引。 我尝试了很多方法,而且都奏效了。 问题是每次重定向都会调用我的index_视图两次。 这是我的顶级URL.py urlpatterns = patterns('', url(r'^$', lambda x: HttpResponseRedirect('/frontend/')), url(r'^frontend/', include('frontend.urls', namespace="frontend")), )

我正在尝试重定向域的/以指向我的“前端”应用程序中的索引。 我尝试了很多方法,而且都奏效了。 问题是每次重定向都会调用我的index_视图两次。 这是我的顶级URL.py

urlpatterns = patterns('',
     url(r'^$', lambda x: HttpResponseRedirect('/frontend/')),
     url(r'^frontend/', include('frontend.urls', namespace="frontend")),
)
这是我的前端/url.py

urlpatterns = patterns('',
    url(r'^$', views.index, name='index'),
    url(r'^alert/create/$', views.create_alert, name="create_alert"),
    url(r'^alert/edit/(\w+)', views.edit_alert, name="edit_alert"),
)
每次我转到/正在调用我的views.index两次,我都不明白为什么=/ 我是否做了错误的重定向


提前感谢您的帮助

您可以将根目录设置为使用FE url模式,如下所示:

urlpatterns = patterns('',
    url(r'^', include('frontend.urls', namespace="frontend")),
)
如果您想强制重定向到/frontend/,则需要一个视图来处理重定向


也许可以查看重定向通用视图:

谢谢您的快速回复。但是我已经尝试过了,我的views.index方法仍然被调用了两次=/基本上,发生的是,对于不是
前端/
映射问题的每个请求,您都会说一个重定向。当你的
create_alert
发布帖子后,当重定向到你的lambda(我不知道你为什么会在那里,你实际上是在把你的url.py变成一个view.bad idea)时,就会触发这个问题。你发出一个重定向,从而两次命中索引,因为索引的regexp与你的重定向相同。谢谢。更改为在视图中执行重定向,并已生效。