我有HttpResponseRedirect()
构造所需url的函数:
我的create
看法:
def create(request):
entry = Char_field(field=request.POST['record'])
entry.save()
return HttpResponseRedirect(reverse('db:index_page',kwargs={'redirected':'true'}))
HttpResponseRedirect()
重定向到的视图是:
def index(request):
redirected = False
template= 'app/index.html'
try:
if request.POST['redirected'] is 'true':
redirected = True
except:
pass
return render(request,template,{'redirected':redirected})
但是它返回一个错误:
NoReverseMatch at /app/create/
Reverse for 'index_page' with arguments '()' and keyword arguments '{'redirected': 'true'}' not found.
网址.py:
urlpatterns = patterns('',
url(r'^$',views.index,name='index_page'),
url(r'^get_record/$',views.get_record,name='get_record'),
url(r'^create/$',views.create_html,name='create_path'),
url(r'^add/$',views.create,name='add_record')
)
为什么会这样?是否可以通过该函数将POST
数据发送到index_page
视图?reverse()