Answer the question
In order to leave comments, you need to log in
Why is the user's photo not saved in the database and in static/images/?
There are no errors, the text is saved and img is not.
models.py:
class Post(models.Model):
date = models.DateTimeField('Создан пост был:', default=timezone.now(), blank=True)
text = models.TextField('Ваши новости:', max_length=1500)
img = models.ImageField('Фотография:', upload_to = 'static/images', blank = True)
def __str__(self):
return self.username
class PostForm(forms.ModelForm):
class Meta:
model = Post
fields = ['text', 'img']
form = PostForm()
if request.method == "POST":
if request.user.is_authenticated == True:
form = PostForm(request.POST, request.FILES)
if form.is_valid():
post = form.save(commit = False)
post.date = timezone.now()
#post.img = request.POST['img']
post.save()
context = Post.objects.order_by('-date')[:5000]
return redirect('/user/profile/news')
return render(request, "fr/addpost.html", {'form': form})
Answer the question
In order to leave comments, you need to log in
date = models.DateTimeField('Создан пост был:', default=timezone.now(), blank=True)
context = Post.objects.order_by('-date')[:5000]
upload_to = 'static/images'
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question