1
我想在處理帶反向的表單後傳遞一個變量,但在嘗試了很多事情之後沒有任何工作。這裏是我的代碼:在django的http響應重定向中使用反向
@login_required(login_url='/accounts/login/')
def pujar_track(request):
if request.method=='POST':
formulari = TrackForm(request.POST, request.FILES)
if formulari.is_valid():
track = formulari.save(commit=False)
track.usuari = request.user
track.save()
url = reverse('acoplar_track', kwargs={'trac_id': track.id})
return HttpResponseRedirect(url)
else:
formulari = TrackForm()
return render(request,'principal/trackForm.html',
{'formulari':formulari})
@login_required(login_url='/accounts/login/')
def acoplar_track(request, track_id):
track = get_object_or_404(Track, id=track_id)
return render_to_response('principal/acoplarTrack.html',
dict(track=track.nom),
context_instance = RequestContext(request))
Url.py
url(r'^track/acoplar/(?P<track_id>\d+)/$',
'principal.views.acoplar_track', name='acoplar_track'),
謝謝!
弄來有何反應? – sneawo 2013-03-14 18:49:30
希望:「如果request.method =='POSfrom django.core.urlresolvers導入reverseT'」是複製/粘貼錯誤? – Brandon 2013-03-14 18:55:36
是的,我已經修改過我的帖子,對錯誤感到抱歉 – user2170928 2013-03-14 19:11:16