325 questions
0
votes
1
answer
27
views
How can I use a field of Foreign key (User Model) as the upload destination of FileField?
I have a Files model which has the User Model as Foreign key, I want to use the user's username as the name of the folder to which the files of the particular user will be uploaded. How can I achieve ...
0
votes
1
answer
47
views
why does self.<FileField_field>.path of an instance of a django model does not match the path where the file was actually uploaded
I am building an app in django (Django==3.1.14).
the app should allow the user to upload zip files (in particular, they are shapefiles).
I want django to upload and manage these files by storing them ...
1
vote
1
answer
79
views
Django File Upload Not Working: Files Not Appearing in Media Directory or Database
I am developing a Django application where users can upload files associated with specific topics and submissions. Despite setting up everything according to the Django documentation, the files do not ...
0
votes
0
answers
422
views
How to Convert and Save Uploaded Video File to M3U8 Format Using Django?
I'm working on a Django project where users can upload video files, and I need to convert these uploaded videos into the M3U8 format for streaming purposes. Could anyone provide guidance or a code ...
0
votes
0
answers
32
views
Does user encoding of uploaded files matter and how to configure it?
I'm making a site on Django. The functionality is as follows - users can download pdf files for processing (converting to different formats, extracting text, etc.).
This is how I receive a file from a ...
1
vote
1
answer
662
views
Django FileField - how to save files to different directories
I have two similar forms for upload files, but I want to save files in different directories depending on the form.
Let me explain, for example:
if User uploaded file from Form_1 -> file should be ...
1
vote
1
answer
193
views
Django model clean function validation error problem
I have a Django model with custom clean function as below:
class License(models.Model):
# fields of the model
def clean(self):
if condition1:
raise ValidationError('Please ...
1
vote
2
answers
5k
views
Django Rest Framework Excel File Upload
Note: Please read the whole question before marking it as duplicate.
Django has changed ALOT Since a couple of years.
I have already tried all the solutions and read Django Rest Framework ...
0
votes
1
answer
729
views
Storing pdf / image or both files in database not in storage/folder in django [closed]
I want to store images and pdf files in the database directly and not in the folder storage, what field type should be given in models along with other information which will be stored in another ...
0
votes
1
answer
183
views
Django cms filer fails to upload file
While trying to upload a file using django cms filer I am getting the following error
`*Internal Server Error: /admin/filer/clipboard/operations/upload/1/
Traceback (most recent call last):
File &...
0
votes
0
answers
266
views
Django - generate a unique suffix to an uploaded file (uuid is cut and django adds another suffix)
I'm going to use DigitalOcean Spaces as a file storage and I want to add suffixes to uploaded filenames for two reasons:
impossible to guess file url with bruteforce
ensure it is unique, as I'm not ...
-1
votes
1
answer
83
views
Image not getting uploaded in Django
I tried to save a record using two different methods but both are not working.
Django Form
Models (create method)
1 I have created a ModelForm
class ProductForm(ModelForm):
class Meta:
...
0
votes
1
answer
152
views
How to upload multiple images with flags to Django
I am building a web page where a blog author can write content and upload images.
Using an image field, I am allowing the author to upload multiple images and with some Javascript logic, I am ...
0
votes
1
answer
194
views
Django updateview (cbv and fbv) to upload multiple files not working
I am trying to upload files (single and multiple) with an UpdateView via an update template but I keep getting a 'This field is required' error when I submit, and the files aren't uploaded, of course. ...
0
votes
0
answers
61
views
Django Model form is showing invalid with initialized values and file
I have a model like this:
class Cohortpdfs(models.Model):
id = models.AutoField(primary_key=True,editable=True)
title= models.CharField(max_length=200,validators=[MaxLengthValidator(100)])
...
0
votes
0
answers
193
views
Django convert InMemoryUploadedFile PDF to images
I need to convert uploaded PDF to images.
I'm using pdf2image function convert_from_path() to convert the image but am getting an error Unable to get page count.
My code looks somewhat like this:
...
2
votes
1
answer
175
views
Use value of primary key in FileField upload_to function
Given the following model I am attempting to use the models ID field (a UUID) in the upload_to path but its defined as None, presumably as it hasn't been generated at that point.
If I use a UUID field ...
0
votes
1
answer
150
views
Infinite POST request on uploading file with Django
I try to upload some files to a server through a web interface with Django.
HTML :
<form method="post" enctype="multipart/form-data" name="upload_file">
{% ...
0
votes
1
answer
344
views
Problems when trying to save an image from react-native to a django model
I am writing my first react-native app with a django backend. for my app to work properly I need to send an image from the device's image library to the django server and then save it in the model. ...
1
vote
1
answer
242
views
MultiValueDictKeyError at /profiles/ uploading file
I am using the django framework. And I just want to upload an image.
So I have this:
views.py:
# Create your views here.
def store_file(file):
with open("temp/mensschappy.png", "wb+...
1
vote
1
answer
2k
views
How to get the file object in `request.data` in Django?
Upload a tar file.
How to get the file object in request.data?
class AlbumViewSet(viewsets.ModelViewSet):
@action(methods=['POST'], detail=False, url_path='upload-album')
def upload_album(...
0
votes
1
answer
42
views
How can my users delete a file that they uploaded using latest Django version?
I'm not getting an error message---but when the Delete button is pressed in my template, nothing happens. Does anyone see what's missing in my code below?
settings.py
MEDIA_URL = '/home/'
MEDIA_ROOT = ...
3
votes
2
answers
2k
views
How to convert bytes into a file the user can download in Django?
I have the bytes of a file saved in my Django database. I want users to be able to download this file.
My question is how do I convert bytes into an actual downloadable file. I know the file name, ...
0
votes
1
answer
519
views
How to save an object with image from views.py in django
In my django project I have to save an image from views.py to the database
here is my models.py
class Mymodel(models.Model):
id=models.IntegerField(unique=True,primary_key=True)
name=models....
0
votes
0
answers
2k
views
how to send image file with json request?
I am working on an e-commerce project, and I want to add products from the front end. The files in my product app in Django is as follows
this is my model.py:
class Product(models.Model):
...
0
votes
1
answer
694
views
Django : transform a function download view into a class view
I am trying to rewrite a function view that download files into a classview.
However I don't see how to do it properly with the right methods, since I have an argument from the url. Then I do not ...
1
vote
1
answer
549
views
How do i upload multiple image file into single models using Django rest framework?
I am stuck to upload a multiple image file at duration of creating doctor model ..
I think to implement multiple upload, you need to set the additional field for uploading in the DoctorSerializer.
I ...
0
votes
0
answers
909
views
How to restrict access to a media-File in Django?
I've an application where my users create a video-file (mp4) which is saved as a Filefield in the model.
In my view I add the object (model) to the context of a TemplateView class.
In my HTML I use ...
0
votes
0
answers
177
views
Is it possible to edit HTML for Django FileResponse via template or view?
I've an application that allows users to add a video. This video is an MP4 format and saved via a FileField to the model. I want to play the video via a fileResponse (view).
This FileResponse plays ...
0
votes
1
answer
75
views
File uploaded in my form is not showing up in my edit/update form
When I fill out my form with its file, it apparently submits, but when checking it out when editing/uploading, all data in the form shows up except my file. So, I cannot access it at all. I guess it ...
0
votes
1
answer
441
views
Django Files Upload from Form get CSRF Forbidden on production
I have a simple Django FileForm for multiple files upload (basically txts with polygon coordinates). I don't want to save the uploaded files anywhere but only treat them on the fly (memory?) and ...
2
votes
1
answer
886
views
Django: how to upload media files to different folders?
I want to save file in automatically created folder related with Employee id_number like:
media->employee->attachments->emp001->emp001.pdf
models.py
from django.db import models
...
0
votes
1
answer
56
views
Is there a way to use files uploaded in django in the template?
I have a django model form where I uploaded images for my app. I am just storing them temporarily locally since its not a real project. The Admin looks like this I'm wondering if there is a way to use ...
0
votes
1
answer
166
views
Django simple upload function
Getting this error:
Exception Type: AttributeError
Exception Value: 'InMemoryUploadedFile' object has no attribute 'save'
When trying to have a Django function as simple as:
def upload(request):
...
0
votes
1
answer
198
views
How to store images using Django forms?
I'm new to django. I've been stuck for a while. I believe everything is configured correctly. However, when my objects are created it is not creating the media directory or storing the files/images. I ...
0
votes
1
answer
72
views
Django file/image upload not responding
I've gone through about 8 tutorials across YouTube and Online websites. I believe everything is configured correctly. However, when my objects are created it is not creating the media directory or ...
0
votes
1
answer
765
views
Django - media files - security
I created a Django app with Video files. I'm using Gunicorn & Nginx. A user (not root) that runs the django server.
I restricted the views so only the users with correct permissions can view these....
0
votes
1
answer
57
views
how to get the last file uploaded to templates
i want to get the last file i was upload and it will be played in templates. but what i make it, every file i was upload, it can be played (so there’s so many audio player). what i want is just show 1 ...
1
vote
1
answer
1k
views
Django : customizing FileField's current file in templates
I am rendering a simple form with a file field.
class ReviewForm(forms.ModelForm):
class Meta:
model = Review
fields = [
'file',
]
widgets = {
...
0
votes
1
answer
35
views
Why is fileChoice.value() None?
I am working in Django 3.2.13 trying to create a simple upload form for a file model with a chained foreign key. I have tried creating a form with a basic form model and a ModelForm, however, even ...
0
votes
1
answer
122
views
form doesn't appear and how to remove <li> in django forms
i have problem. why my form doesn't show except i clicked submit button. is that any problem with my code?
here's my html code :
<form method="POST" enctype="multipart/form-data"...
1
vote
2
answers
2k
views
What's the difference between MEDIA_ROOT = BASE_DIR / 'media'` and MEDIA_ROOT= os.path.join(BASE_DIR, "media") in Django setting.py
I wanted to know the difference between using MEDIA_ROOT = BASE_DIR / 'media' and MEDIA_ROOT= os.path.join(BASE_DIR, "media") in settings.py.
0
votes
1
answer
1k
views
how to change folder location to save file - DJANGO FileSystemStorage
so i want when i upload a file, the file will go to media/mp3 not media/txt. how to change save file location?
views.py:
def homepage(request):
if request.method == "POST":
form = ...
2
votes
1
answer
463
views
Reopening a closed django InMemoryFileUpload using class based views
I have a Django project which involves a user uploading a CSV file via a form. I parse this file in the forms clean method, and then in the views form_valid method I want to read the file data again (...
1
vote
0
answers
261
views
I'm trying to display pdf a file that i uploaded django FileField but it's not work
hello guys i try to display pdf file in my html page.
i have this models:
class HomeWork(models.Model):
nameFile = models.CharField('Name File',max_length=30)
file = models.FileField('File',...
0
votes
1
answer
631
views
How to upload any type of file in Django? [duplicate]
I want to accept any type of file from the user and save it in the database. I am using following code:
In HTML file :
<input type="file" name="file_name" required>
But when ...
0
votes
2
answers
368
views
django file opens locally but fails in server
What I wanted to achieve was for a user to upload a file through a form, lets say profile picture,
My aim is to take that file, send it through imgbb's api and get the image url to store for use in my ...
0
votes
1
answer
912
views
How do I upload a file in Django OneToOne Model's FileField using form?
I have one model Detail which has OneToOne relation with default User Model. I have a field FileField in my Detail model, where I want to upload the files using forms from frontend/templates.
I have ...
0
votes
1
answer
781
views
how to use font awesome icon as file upload input field for django template as bootstrap?
I am using bootstrap as the template. The form is designed as the font awesome icon will be the file upload field in the design.
Is there any way to do it? I have no idea about that. I am sharing the ...
0
votes
1
answer
1k
views
Why file extension validator is not working properly in django?
I am trying to add a file extension validator in the Filefield of my model.
But when I am adding a different extension file through my serializer it's adding the extensions I didn't put in my ...