S
S
SHADRIN2020-06-28 15:09:48
Django
SHADRIN, 2020-06-28 15:09:48

Why doesn't django render forms on the server?

A simple file upload page, everything works locally, but as soon as I upload it to the server, it does not display the file selection button.
Local
5ef888118c441587843790.png
Server
5ef8882cd7549077463317.png

views

from django.views.generic.edit import FormView
from .forms import FileFieldForm
from django.shortcuts import render
from django.conf import settings
from django.core.files.storage import FileSystemStorage
import paramiko
import glob
import os
from .models import Analiticks

class FileFieldView(FormView):
    form_class = FileFieldForm
    template_name = 'mainpage/upload.html'
    success_url = 'analize' 

    def post(self, request, *args, **kwargs):
        form_class = self.get_form_class()
        form = self.get_form(form_class)
        files = request.FILES.getlist('attachments')
        if form.is_valid():
            filesystem = FileSystemStorage()
            for f in files:
                pass
                filename = filesystem.save(f.name, f)
            return self.form_valid(form)
        else:
            return self.form_invalid(form)


forms
class FileFieldForm(forms.Form):
    attachments = forms.FileField(widget=forms.ClearableFileInput(attrs={'multiple': True}))

upload.html
<form enctype="multipart/form-data" method="post">
    {% csrf_token %}
    {{ form.attachments }}
    <button type="submit">Анализировать</button>
</form>

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question