Хочу загрузить фотографию пользавателя.
Ошибка :
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/rassul/ononline/ononline/user/views.py", line 90, in profile
imgform = UserImageForm(request.POST, request.FIELS)
AttributeError: 'WSGIRequest' object has no attribute 'FIELS'
Models.py:
from django.db import models
from django.contrib.auth.models import AbstractUser
from django.utils import timezone
from django import forms
from django.forms import ModelForm
from django.contrib.auth import get_user_model
class User(AbstractUser):
weburl = models.CharField(max_length=200, null = True, blank = True)
webname = models.CharField(max_length=50, null = True, blank = True)
image = models.ImageField('Фото пользавателя', upload_to = 'static/images', blank = True)
def __str__(self):
return self.username
class UserImageForm(ModelForm):
User = get_user_model()
class Meta:
model = User
fields = ['image']
Views.py:
User = get_user_model()
if request.method == "POST":
if request.user.is_authenticated == True:
imgform = UserImageForm(request.POST, request.FIELS)
print(5)
if imgform.is_valid():
imgform.save()
return render(request, "fr/profile.html", {'posts': posts, 'tz': tz})
youquery = User.objects.order_by('image').last()
return render(request, "fr/profile.html", {'youtemplate':youtemplate,'youquery': youquery,'posts': posts, 'tz': tz})
profile.html:
<form method = "POST", enctype="multipart/form-data">
{% csrf_token %}
{{youtemplate.as_p}}
<button style = 'width: 120px; height: 30px; margin-left: 40px; margin-top: -9px; background-color: rgb(17, 240, 9);' type = 'submit'>Сохранить</button>
</form>