i want the username when the user signUp
class SignUp(generic.CreateView):
form_class = UserCreationForm
success_url = reverse_lazy('login')
template_name = 'signup.html'
i need to access the username of the user who has been signed up .
You can access the post data with request.POST
. You can override the post
request of the CreateView
and add the specific code to do what you want with the username and then continue with the default flow of the CreateView
post
method/
def post(self, request, *args, **kwargs):
username = request.POST.get('username')
# do something with the username
# and continue
self.object = None
return super().post(request, *args, **kwargs)
If you need to use the user after it has been stored in the database you could modify the create
method of the serializer instead of modifying the post
.
class UserCreationForm:
def create(self, validated_data):
user = super().create(validated_data)
username = user.username
# do something with the username or the user
return user
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments