[英]Django redirecting from one view to another
I'm trying to redirect to a view function from another using djando redirect().我正在尝试使用 djando redirect() 从另一个重定向到视图函数。
def view1(request):
message="hello! redirection was done!!"
return render(request,'test.html',locals())
def view2(request):
return redirect(view1)
but I'm getting NoReverseMatch exception.但我收到 NoReverseMatch 异常。 My urls.py is as shown below
我的urls.py如下图
from django.conf.urls import url
from django.contrib import admin
from .views import signup,auth_test,redirected,view2
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^signup/$' ,signup),
url(r'^login/$', auth_test),
url(r'^simple',view2)
#url(r'^locallibrary.views.redirected/$',redirected)
]
any help will be appreciated thank you任何帮助将不胜感激谢谢
error page错误页面
NoReverseMatch at /simple
Reverse for 'locallibrary.views.view1' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []
Request Method: GET
Request URL: http://127.0.0.1:8000/simple
Django Version: 1.10.4
Exception Type: NoReverseMatch
Exception Value:
Reverse for 'locallibrary.views.view1' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []
Exception Location: C:\Users\Hp\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\urls\resolvers.py in _reverse_with_prefix, line 392
Python Executable: C:\Users\Hp\AppData\Local\Programs\Python\Python35-32\python.exe
Python Version: 3.5.2
Python Path:
['C:\\Users\\Hp\\PycharmProjects\\locallibrary',
'C:\\Program Files (x86)\\JetBrains\\PyCharm 145.597.11\\helpers\\pycharm',
'C:\\Users\\Hp\\PycharmProjects\\locallibrary',
'C:\\Users\\Hp\\AppData\\Local\\Programs\\Python\\Python35-32\\python35.zip',
'C:\\Users\\Hp\\AppData\\Local\\Programs\\Python\\Python35-32\\DLLs',
'C:\\Users\\Hp\\AppData\\Local\\Programs\\Python\\Python35-32\\lib',
'C:\\Users\\Hp\\AppData\\Local\\Programs\\Python\\Python35-32',
'C:\\Users\\Hp\\AppData\\Local\\Programs\\Python\\Python35-32\\lib\\site-packages']
Server time: Sun, 5 Feb 2017 12:31:15 +0530
You have to add view1
to url patterns also:您还必须将
view1
添加到 url 模式:
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^signup/$' ,signup),
url(r'^login/$', auth_test),
url(r'^simple',view2),
url(r'^simple2',view1)
]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.