Captured URL parameters in form

前端 未结 2 816
一整个雨季
一整个雨季 2021-01-15 01:09

I am using Userena and I am trying to capture URL parameters and get them to my form but I\'m lost how to do this.

What I would like to do in my template is:

2条回答
  •  一个人的身影
    2021-01-15 01:55

    You can access the url in your template using -

    {% request.get_full_path %}
    

    (see the docs for more info).

    However if you just want to get the planslug variable then pass it from the view to the template and access it in the template (it's available in the view because it's a named parameter in the url) -

    def signup(request, planslug=None):
        #
        render(request, 'your_template.html', {'planslug':planslug}
    

    and then in your template you get it with -

    {% planslug %}
    

    If you're using class based views then you'll need to override get_context_data to add the planslug variable to your context before you pass it to the template-

    def get_context_data(self, *args, **kwargs):
        context = super(get_context_data, self).get_context_data(*args, **kwargs)
        context['planslug'] = self.kwargs['planslug']
        return context
    

提交回复
热议问题