我正在尝试使用djando redirect()重定向到另一个视图函数。
def view1(request):
message="hello! redirection was done!!"
return render(request,'test.html',locals())
def view2(request):
return redirect(view1)
但我得到NoReverseMatch异常。我的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)
]
任何帮助将不胜感激
错误页面
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
答案 0 :(得分:2)
您还必须将view1
添加到网址格式:
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^signup/$' ,signup),
url(r'^login/$', auth_test),
url(r'^simple',view2),
url(r'^simple2',view1)
]