Home > Software engineering >  Django - Accessing extra ModelForm fields in a different template
Django - Accessing extra ModelForm fields in a different template

Time:12-20

I have a first view (createview) which calls a ModelForm that has an extra field added to it. The first view leads to a second view (detailview), where i need to access the fields from the previous ModelForm to show them in the template. For the fields belonging to the model, i used {{ object.fieldname }} in the template and it works. The problem that remains is how to access the field i added myself.

Thank you for your help

CodePudding user response:

Use Django Session. Chexk on the link in doccumentation

in your form view

    if form.is_valid():
                request.session['extra_field'] = form.cleaned_data['extra_field']
...

On the next page view get back the saved data on session

def your_checkout_view(request):
    extra_field = request.session['extra_field']
...
  • Related