I am trying to initialize a Django form with a parameter from a view. However when i try to use the kwargs in the form's init, i get that it's always empty. Why could it be? Am i missing something?
My view (filename: “FirstView.py”):
def create_userStory(request, proyect_id):
if request.method=='POST':
auxForm = UserStoryForm(request.POST, proyect_id=proyect_id)
My form (filename: “forms.py”):
class UserStoryForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
proyectId = kwargs.pop('proyect_id', None)
super(UserStoryForm, self).__init__(*args, **kwargs)
team = Team.objects.get(proyect_id=proyectId)
I tried debugging/printing the kwargs in my form, but i always get {}, meaning that the parameter from the view did not pass.
Previously i tryied to follow these existing questions:
django form: Passing parameter from view.py to forms gives out error