django 用户删除自已发布的信息的时候.怎么取得自已的id? 代码里总得取不到
在代码里这样定义的删除url
url(r'^info/?id=(?P<pk>\d+)/del/$', 'gqinfo.views.info_del', name='info_del'),
@login_required
def info_del(request):
gqinfo_del=Gqinfo.objects.get(id=pk)
if gqinfo_del.user != request.user:
return HttpResponseForbidden()
gqinfo_del.delete()
return HttpResponseRedirect('/')
@login_required
def info_del(request):
if request.GET.has_key('gqinfo_id'):
gqinfo_id = request.GET['gqinfo_id']
try:
gqinfo_del=Gqinfo.objects.get(id=gqinfo_id)
if gqinfo_del.user != request.user:
return HttpResponseForbidden()
else:
gqinfo_der.delete()
except:
return Http404
return HttpResponseRedirect('/')
else:
return Http404
@login_required
def info_del(request, pk):
# can use pk now
...