media file upload

14 views
Skip to first unread message

Luca Bertolotti

unread,
Sep 18, 2019, 12:38:36 PM9/18/19
to Django users
Hello i can't upload the file, i'm in a debug mode:

the urls.is:

from django.contrib import admin
from django.urls import path, include
from django.conf import settings
from django.conf.urls.static import static


urlpatterns = [
    path('', include('polls.urls')), 
    path('admin/', admin.site.urls),
    
    
]
if settings.DEBUG is True:
    urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

The model is:

class Disegni(models.Model):
    iddisegni = models.AutoField(primary_key=True)
    descrizione = models.CharField(max_length=45, blank=True, null=True)
    revisione = models.CharField(max_length=45, blank=True, null=True)
    file = models.FileField(upload_to='disegni/', blank=True, null=True)

    class Meta:
        managed = False
        db_table = 'disegni'

the forms is:
class DisegniForm(forms.ModelForm):
    
    class Meta:
        model = Disegni
        fields = ('iddisegni', 'descrizione', 'revisione', 'file')
        labels = {'descrizione':'Descrizione', 'revisione':'Revisione', 'file':'File'}


The settings.py is:

STATIC_URL = '/static/'
MEDIA_URL = '/media/'
STATIC_ROOT = "E:/dngo/mysite/polls/static"
MEDIA_ROOT = "E:/dngo/mysite/polls/media"

the template is generated 

The template is just : 

{% load static %}
<head>
<link rel="stylesheet" href="{%static "regole.css" %}">
</head>
<form form action="salvo_nuovo" method="post">{% csrf_token %}
    {{ form.as_p }}
    <button type="submit">Salva</button>
</form>   


I never get errors but the file is not uploaded
Where is my mistake?

mohammed habib

unread,
Sep 18, 2019, 1:29:00 PM9/18/19
to django...@googlegroups.com
Make sure to add ‘enctype="multipart/form-data"’ to your form tag, so that the file data is included in when the form is submitted

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/a8713cc3-2a4c-42ba-8c54-976e1a4b8090%40googlegroups.com.

Luca Bertolotti

unread,
Sep 19, 2019, 2:47:00 AM9/19/19
to Django users
Thanks

Luca
To unsubscribe from this group and stop receiving emails from it, send an email to django...@googlegroups.com.
Reply all
Reply to author
Forward
Message has been deleted
0 new messages