Показывает ERROR 405 в браузере и метод не разрешен в оболочке - Django
Я создаю сайт, который имеет 2 типа пользователей.
Форма регистрации работает нормально, но форма входа и форма добавления товаров выдает HTTP 404 ERROR в браузере и показывает метод не разрешен в оболочке.
Вот все коды проекта:
seller/forms.py
def login_seller(request):
if request.user.is_authenticated:
return redirect('home')
else:
if request.method=='POST':
logform = AuthenticationForm(data=request.POST)
if logform.is_valid():
username = form.cleaned_data.get('username')
password = form.cleaned_data.get('password')
user = authenticate(username=username, password=password)
if user is not None :
login(request,user)
return redirect('home')
else:
messages.error(request,"Invalid username or password")
else:
messages.error(request,"Invalid username or password")
return render(request, 'Seller/login-seller.html',
context={'logform':AuthenticationForm()})
seller/models.py
from django.db import models
from Accounts.models import CustomUser
class SellerProfile(models.Model):
user = models.OneToOneField(CustomUser, on_delete= models.CASCADE)
name = models.CharField(max_length= 90)
email = models.EmailField(max_length = 90, unique = True)
store_name = models.CharField(max_length = 30, unique = True)
def __str__(self):
return self.name
products/models.py
CATEGORY_CHOICES = [
("ILLUSTRATION", "Digital Illustration"),
("EBOOKS", "eBooks"),
("PHOTOGRAPHS", "Photographs"),
("COMICS", "Comics"),
]
class Products(models.Model):
seller = models.ForeignKey(SellerProfile, on_delete = models.CASCADE)
title = models.CharField(max_length = 255)
product_category = models.CharField(choices = CATEGORY_CHOICES, max_length = 100, default = 'eBooks')
description = models.TextField()
price = models.DecimalField(max_digits=10, decimal_places=2)
discounted_price = models.DecimalField(max_digits=10, decimal_places=2, default = 0.00)
thumbnail = models.ImageField(upload_to = 'media/thumbnail/',null=True, blank = True)
files = models.FileField(upload_to = 'media/product_files/', null = True, blank = True)
slug = models.SlugField(max_length = 255, unique = True, null = True, blank = True)
is_featured = models.BooleanField(default = False)
is_published = models.BooleanField(default = True)
def __str__(self):
return self.title
product/forms.py
from django import forms
from django.forms import ModelForm
from .models import Products
class ProductForm(forms.ModelForm):
class Meta:
model = Products
fields = ['title', 'product_category', 'description', 'price', 'discounted_price', 'thumbnail', 'files']
product/views.py
class AddProductsView(View):
def post(self, request, *args, **kwargs):
product_form = ProductForm(request.POST, request.FILES)
if product_form.is_valid():
new_product = product_form.save(commit = False)
new_product.seller = request.seller
new_product.save()
context = {
'product_form' : product_form
}
return render(request, 'Seller/product-form.html', context)
Как я могу решить эту проблему? Любое предложение будет очень полезным. Спасибо