[英]Django: dynamically mapping views in urls.py
I have a views
directory containing say a hundred view files.我有一个
views
包含目录说一百查看文件。 How can i make my urls.py
transfer control to these view files without putting in an "intermediate handler" as described here (answered 3 years back).我怎样才能让我的
urls.py
将控制权转移到这些视图文件而不像这里描述的那样放入“中间处理程序”(3年前回答)。
Basically- is there a cleaner way for redirecting control to views in django?基本上 - 是否有一种更简洁的方法可以将控制重定向到 django 中的视图?
The view function returns an HTML page that includes the current date and time. view 函数返回一个包含当前日期和时间的 HTML 页面。 To display this view at a particular URL, you'll need to create a URLconf;
要在特定 URL 上显示此视图,您需要创建一个 URLconf; see URL dispatcher for instructions.
有关说明,请参阅 URL 调度程序。
https://docs.djangoproject.com/en/1.7/topics/http/urls/ https://docs.djangoproject.com/en/1.7/topics/http/urls/
For redirecting you should use the Django redirect shortcut function对于重定向,您应该使用 Django 重定向快捷功能
from django.shortcuts import redirect
def my_view(request):
...
return redirect('some-view-name', foo='bar')
https://docs.djangoproject.com/en/1.7/topics/http/shortcuts/#redirect https://docs.djangoproject.com/en/1.7/topics/http/shortcuts/#redirect
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.