Django将链接中的其他参数传递给另一个视图

时间:2014-01-28 06:00:14

标签: python django

我有一个页面drag.html,在此网址上提供 http://localhost:8000/dashboard?wid=ca1480f&ref_url=localhost&adpart=left此页面有一个链接

<a id="btn-start" href="/dashboard/save" class="btn">Save Reward</a>

当用户点击此链接时,它会重定向到SaveRewardview我要保存链接中存在的所有信息,wid=ca1480f&ref_url=localhost&adpart=left

urls.py

url(r'^dashboard$', login_required(CouponPageView.as_view()), name='dashboard'),
url(r'^dashboard/save$', login_required(SaveRewardView.as_view()), name=''),

model.py

class SaveReward(models.Model):
  widget = EmbeddedModelField(Widget)
  campaign = EmbeddedModelField(Campaign)
  coupon_part = models.CharField(max_length=200)
  saved_on = models.DateTimeField(auto_now_add=True)

def __unicode__(self):
    return self.widget.widget_name

Views.py

class SaveRewardView(TemplateView):

  #Here how i will get wid , ref_url, adpart which is present in url parameters

1 个答案:

答案 0 :(得分:2)

你可以直接在url中给出参数。

<a id="btn-start" href="/dashboard/?{{request.META.QUERY_STRING}}" class="btn">Save Reward</a>

网址是:

url(r'^dashboard/$', login_required(CouponPageView.as_view()), name='dashboard'),