As we have made a signup module, so it is obvious we are going to need a profile update module. For Profile Update Functionality, we are going to use generic UpdateView. These are the in-built class-based views that make our code DRY. We are going to use the User Model which we have used above.
forms.py
from django import forms
from django.contrib.auth.models import User
# Profile Form
class ProfileForm(forms.ModelForm):
class Meta:
model = User
fields = [
'username',
'first_name',
'last_name',
'email',
]
views.py
from django.shortcuts import render
from django.urls import reverse_lazy
from django.views.generic import CreateView, UpdateView
from core.forms import SignUpForm, ProfileForm
from django.contrib.auth.models import User
# Edit Profile View
class ProfileView(UpdateView):
model = User
form_class = ProfileForm
success_url = reverse_lazy('home')
template_name = 'commons/profile.html'
urls.py
from django.urls import path
from core.views import SignUpView, ProfileView
urlpatterns = [
path('signup/', SignUpView.as_view(), name='signup'),
path('profile/<int:pk>/', ProfileView.as_view(), name='profile'),
]