how to initialize input form fields using URL parameters

44 views
Skip to first unread message

Andrew Brown

unread,
Jan 22, 2023, 8:08:43 PM1/22/23
to Django users
I am trying to pass initial values to my form set via URL Query
ex) Localhost:8000?/First_name_id_0=Samuel
forms.py.png

I was told to use the initial parameter and not the instance in my view first

"An inline formset is related to one instance of the parent model. You identify which instance the formset is related to by the “instance” parameter. The “initial” parameter has a different usage, which is defined in the docs."

But I can't seem to find an examples in the docs
Views.py.png

How do I change my view so that that it initialize my form set with URL Query?

Michael Maina

unread,
Jan 23, 2023, 10:03:56 AM1/23/23
to Django users
Hello,

You need to start from the urls.py file and define a path that looks close this  

your_path/<int: variable_data> or your_path/<str: variable_data>

Then change your view to handle the new parameter

def form_view(request, variable_data):

Within your view you can now manipulate this parameter through a variable/function/class

Hope this is of help.

The backend is the easy part, front-end needs to be stitched right to generate pass variable data accurately with minimal user input for data sanity.


Reply all
Reply to author
Forward
0 new messages