Django响应重定向变量url

时间:2011-05-06 09:32:01

标签: django

我在一个带有变量网址/emails/edit/32/的网页上,我想更新表单并刷新页面...如何向当前页面发出HttpResponseRedirect,该页面具有可变扩展名?

我的urls.py是:

urlpatterns = patterns('',
    (r'^emails/edit/$', 'email_edit'),    # this is the page it is re-directing to
    (r'^emails/edit/(?P<email_id>\d+)/$', 'emails_single'),
)

我的views.py是:

def emails_single(request, email_id):
    ...(stuff)...
    Email.objects.filter(id=request.POST['id']).update(email=request.POST['email'])
        return HttpResponseRedirect(reverse('emails_single',args=[email_id]))

更新:它正在做的只是切断URL的结尾(即使使用反向示例)。例如:http://127.0.0.1:8000/emails/edit/42/ - &gt; http://127.0.0.1:8000/emails/edit/

3 个答案:

答案 0 :(得分:2)

from django.core.urlresolvers import reverse

return HttpResponseRedirect(reverse('emails_single', args=[email_id]))

答案 1 :(得分:1)

答案 2 :(得分:0)

from django.core.urlresolvers import reverse

def myview(request):
    return HttpResponseRedirect(reverse('urlname', args=[1945]))