[Answer]-Form interceptor, populate a form field without touching the original application

1👍

You can add this line in view after form module import and before creating form instance (not using middleware):

from app.forms import AppForm
AppForm.base_fields['fieldname'].initial="your default value"

Middleware may looks like:

class InitialValues(object):
    def process_request(self, request):
        from app.forms import AppForm
        AppForm.base_fields['fieldname'].initial="your default value"   

It executes before view. You cant insert middleware into template rendering, only before and after view.

👤eri

Leave a comment