P4YK
@P4YK

Как исправить ошибку UserOurRegistration?

Ошибка: 609fe0d62d844193744074.jpeg

forms.py :
from django import forms                                                               
from django.contrib.auth.models import User                                            
from .models import Profile                                                            
from django.contrib.auth.forms import UserCreationForm                                 
                                                                                       
class UserRegisterForm(UserCreationForm):                                              
    email = forms.EmailField()                                                         
                                                                                       
    class Meta:                                                                        
        model = User                                                                   
        fields = ['username', 'email', 'password1', 'password2']                       
                                                                                       
                                                                                       
class UserUpdateForm(forms.ModelForm):                                                 
    email = forms.EmailField()                                                         
                                                                                       
    class Meta:                                                                        
        model = User                                                                   
        fields = ['username', 'email']                                                 
                                                                                       
                                                                                       
class ProfileUpdateForm(forms.ModelForm):                                              
    class Meta:                                                                        
        model = Profile                                                                
        fields = ['image']


Views.py :
from django.shortcuts import render, redirect                                          
from django.contrib import messages                                                    
from .forms import UserOurRegistration                                                 
from .forms import UserRegisterForm, UserUpdateForm, ProfileUpdateForm                 
                                                                                       
                                                                                       
def register(request):                                                                 
    if request.method == "POST":                                                       
        form = UserOurRegistration(request.POST);                                      
        if form.is_valid():                                                            
            form.save()                                                                
            username = form.cleaned_data.get('username')                               
            return redirect('home')                                                    
    else:                                                                              
        form = UserOurRegistration()                                                   
    return render(request, 'users/registration.html', {'form': form})                  
                                                                                       
@login_required                                                                        
def profile(request):                                                                  
    if request.method == 'POST':                                                       
        u_form = UserUpdateForm(request.POST, instance=request.user)                   
        p_form = ProfileUpdateForm(request.POST,                                       
                                   request.FILES,                                      
                                   instance=request.user.profile)                      
        if u_form.is_valid() and p_form.is_valid():                                    
            u_form.save()                                                              
            p_form.save()                                                              
            messages.success(request, f'Your account has been updated!')               
            return redirect('profile')                                                 
                                                                                       
    else:                                                                              
        u_form = UserUpdateForm(instance=request.user)                                 
        p_form = ProfileUpdateForm(instance=request.user.profile)                      
                                                                                       
    context = {                                                                        
        'u_form': u_form,                                                              
        'p_form': p_form                                                               
    }                                                                                  
                                                                                       
    return render(request, 'users/profile.html', context)
  • Вопрос задан
  • 30 просмотров
Решения вопроса 1
sergey-gornostaev
@sergey-gornostaev Куратор тега Django
Седой и строгий
В forms.py нет UserOurRegistration.
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы