i am trying to get data to be autofilled that i am getting from a code generator . so without needing a user to fill it in i want it to be already filled
from django.utils.crypto import get_random_string
unique_id = get_random_string(length=32)
class UserRegisterForm(UserCreationForm):
email = forms.EmailField()
class Meta:
model = User
fields = ['username','email','password1','password2']
class Bybitapidata(ModelForm):
class Meta:
model = Bybitapidatas
fields = ('apikey','apisecret','sectoken')
widgets = {
'apikey': TextInput(attrs={
'class': "form-control",
'style': 'max-width: 300px;',
'placeholder': 'Bybit Api Key'
}),
'apisecret': TextInput(attrs={
'class': "form-control",
'style': 'max-width: 300px;',
'placeholder': 'Bybit Api Secret'
}),
'sectoken': TextInput(attrs={
'class': "form-control",
'style': 'max-width: 300px;',
'placeholder': 'Please enter a 12 Digit token'#here i want to automatically give 12 digits that is being generated
})
}
CodePudding user response:
Try to generate a random token with one of this options that i give to you, I hope you like it! :)
import secrets
token_generator = token_urlsafe(16)
'sectoken': TextInput(attrs={
'class': "form-control",
'style': 'max-width: 300px;',
'placeholder': token_generator
})
}
Another example:
import string
import random
length= 16
token_generator =''.join(random.choices(string.ascii_letters string.digits,k=length))