1👍
Pass in the request method when you instantiate this form. You can check for request method with:
post = request.method == 'POST'
The you can pass this into the modified __init__
below.
class BitbucketCreateRepoForm(forms.Form):
def __init__(self, repo_name=None, post=False, *args, **kwargs):
if repo_name and post:
self.repo_name = json.dumps(repo_name).strip()
super(BitbucketCreateRepoForm, self).__init__()
username = forms.ChoiceField(required=True, initial='codyc54321', choices=BITBUCKET_USERNAME_CHOICES)
repo_name = forms.CharField(required=True, label='Repo name')
description = forms.CharField(widget=forms.Textarea, required=False)
UPDATE:
I was typing as you modified your question. In order to get the string representation of a QueryDict object simply import json
then json.dumps(repo_name)
. Hope that helps.
Source:stackexchange.com