Answer the question
In order to leave comments, you need to log in
Does not save media files. What to do?
Post creation function:
if req.method == 'POST':
post = Post()
post.owner = req.user
post.likes = 0
post.views = 0
post.spoiler = req.POST.get('spoiler', False)
post.title = req.POST['title']
post.text = req.POST['text']
post.save()
<form method="post" action="{% url 'main' %}">
{% csrf_token %}
<input autocomplete="off" class="new-form-input" name="title" placeholder="Header...">
<textarea autocomplete="off" autofocus class="comment-form" name="text" placeholder="Text..."></textarea><br><br>
<span class="logo">Spoiler of the article:</span><br>
<input class="comment-form" accept="image/*" name="spoiler" type="file" required><br>
<button type="submit">Publish ✅</button>
<br>
</form>
<input class="comment-form" accept="image/*" name="spoiler" type="file" required>
is not saved. post.spoiler = req.POST.get('spoiler', False)
Answer the question
In order to leave comments, you need to log in
I think it's not enough for me
enctype="multipart/form-data"
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question