Profile Update View Form After Sign Up in Django
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.
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'
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', ]
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'), ]
profile.html
{% extends 'base.html' %} {% block title %}Profile Page{% endblock title %} {% block content %} <h2>Profile Page</h2> <form method="post"> {% csrf_token %} {{ form.as_p }} <button type="submit">Update</button> <br><br> <a href="{% url 'home' %}">Back</a> </form> {% endblock content %}
Sign up here with your email
ConversionConversion EmoticonEmoticon