Y
Y
y_o_l_k_i_n___e_g_o_r2021-05-29 19:22:05
Django
y_o_l_k_i_n___e_g_o_r, 2021-05-29 19:22:05

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()


html code of the page with post creation:
<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>


Photo from
<input class="comment-form" accept="image/*" name="spoiler" type="file" required>
is not saved.
I think it's in , but I don't know how to fix it. You need to solve the problem without creating a post creation form, only a function, without classes. post.spoiler = req.POST.get('spoiler', False)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Melnikov, 2021-05-29
@y_o_l_k_i_n___e_g_o_r

I think it's not enough for me
enctype="multipart/form-data"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question