我试图让用户在退出时收藏视频。我正在使用@login_required 强制用户登录,将视频保存到他们的帐户,然后重定向回他们所在的页面。我收到一条错误消息
UnboundLocalError at /loggedout_fav/
local variable 'video' referenced before assignment
在loggedout_fav 下的返回行上。我在视图中放置了一条打印语句,但也没有任何内容打印到控制台。关于如何解决它的任何建议?
html
<form method = 'post' action = '/loggedout_fav/'> {% csrf_token %}
<input type="hidden" value="{{video}}" name = "video_add_loggedout"/>
<input type='submit' value='Login to plate this video'/>
</form>
网址
url(r'^loggedout_fav/', 'loggedout_fav'),
看法
def loggedout_fav(request):
if 'video_add_loggedout' in request.POST:
video = request.POST['video_add_loggedout']
print video
print 'test'
try:
s = Everything.objects.get(profile = request.user, video = request.POST['video_add_loggedout'], playlist = 'Favorites', platform = 'youtube')
print "already exists"
except:
p = Everything(profile = request.user, video = request.POST['video_add_loggedout'], playlist = 'Favorites', platform = 'youtube')
p.save()
return HttpResponseRedirect(reverse('reserve.views.trending_video_player', kwargs={'author':'youtube', 'video':video}))
def trending_video_player(request,author,video):
...